home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / etc / bash_completion < prev    next >
Encoding:
Text File  |  2009-02-05  |  221.5 KB  |  9,709 lines

  1. #   bash_completion - programmable completion functions for bash 3.x
  2. #              (backwards compatible with bash 2.05b)
  3. #
  4. #   Copyright ¬© 2006-2008, Ian Macdonald <ian@caliban.org>
  5. #             ¬© 2008, David Paleino <d.paleino@gmail.com>
  6. #             ¬© 2008, Luk Claes <luk@debian.org>
  7. #
  8. #   This program is free software; you can redistribute it and/or modify
  9. #   it under the terms of the GNU General Public License as published by
  10. #   the Free Software Foundation; either version 2, or (at your option)
  11. #   any later version.
  12. #
  13. #   This program is distributed in the hope that it will be useful,
  14. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #   GNU General Public License for more details.
  17. #
  18. #   You should have received a copy of the GNU General Public License
  19. #   along with this program; if not, write to the Free Software Foundation,
  20. #   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. #   The latest version of this software can be obtained here:
  23. #
  24. #   http://bash-completion.alioth.debian.org/
  25. #
  26. #   RELEASE: 20080617.5
  27.  
  28. if [[ $- == *v* ]]; then
  29.     BASH_COMPLETION_ORIGINAL_V_VALUE="-v"
  30. else
  31.     BASH_COMPLETION_ORIGINAL_V_VALUE="+v"
  32. fi
  33.  
  34. if [[ -n $BASH_COMPLETION_DEBUG ]]; then
  35.     set -v
  36. else
  37.     set +v
  38. fi
  39.  
  40. # Alter the following to reflect the location of this file.
  41. #
  42. [ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=/etc/bash_completion
  43. [ -n "$BASH_COMPLETION_DIR" ] || BASH_COMPLETION_DIR=/etc/bash_completion.d
  44. readonly BASH_COMPLETION BASH_COMPLETION_DIR
  45.  
  46. # Set a couple of useful vars
  47. #
  48. UNAME=$( uname -s )
  49. # strip OS type and version under Cygwin (e.g. CYGWIN_NT-5.1 => Cygwin)
  50. UNAME=${UNAME/CYGWIN_*/Cygwin}
  51. RELEASE=$( uname -r )
  52.  
  53. # features supported by bash 2.05 and higher
  54. if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} > 04 ]] ||
  55.    [ ${BASH_VERSINFO[0]} -gt 2 ]; then
  56.     declare -r bash205=$BASH_VERSION 2>/dev/null || :
  57.     default="-o default"
  58.     dirnames="-o dirnames"
  59.     filenames="-o filenames"
  60. fi
  61. # features supported by bash 2.05b and higher
  62. if [ ${BASH_VERSINFO[0]} -eq 2 ] && [[ ${BASH_VERSINFO[1]} = "05b" ]] ||
  63.    [ ${BASH_VERSINFO[0]} -gt 2 ]; then
  64.     declare -r bash205b=$BASH_VERSION 2>/dev/null || :
  65.     nospace="-o nospace"
  66. fi
  67. # features supported by bash 3.0 and higher
  68. if [ ${BASH_VERSINFO[0]} -gt 2 ]; then
  69.     declare -r bash3=$BASH_VERSION 2>/dev/null || :
  70.     bashdefault="-o bashdefault"
  71.     plusdirs="-o plusdirs"
  72. fi
  73.  
  74. # Turn on extended globbing and programmable completion
  75. shopt -s extglob progcomp
  76.  
  77. # A lot of the following one-liners were taken directly from the
  78. # completion examples provided with the bash 2.04 source distribution
  79.  
  80. # Make directory commands see only directories
  81. complete -d pushd
  82.  
  83. # The following section lists completions that are redefined later
  84. # Do NOT break these over multiple lines.
  85. #
  86. # START exclude -- do NOT remove this line
  87. complete -f -X '!*.?(t)bz?(2)' bunzip2
  88. # TODO: see #455510
  89. #complete -f -X '!*.?(t)bz?(2)' bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep
  90. complete -f -X '!*.*' bzcat bzcmp bzdiff bzegrep bzfgrep bzgrep
  91. complete -f -X '!*.@(zip|ZIP|jar|JAR|exe|EXE|pk3|war|wsz|ear|zargo|xpi|sxw|ott|od[fgpst])' unzip zipinfo
  92. complete -f -X '*.Z' compress znew
  93. complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' gunzip
  94. # TODO: see #455510
  95. #complete -f -X '!*.@(Z|gz|tgz|Gz|dz)' zcmp zdiff zcat zegrep zfgrep zgrep zless zmore
  96. complete -f -X '!*.*' zcmp zdiff zcat zegrep zfgrep zgrep zless zmore
  97. complete -f -X '!*.Z' uncompress
  98. complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' ee
  99. complete -f -X '!*.@(gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|svg|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX|SVG)' display
  100. complete -f -X '!*.@(gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|GIF|JPG|JP?(E)G|TIF?(F)|PNG|P[BGP]M|BMP|X[BP]M|RLE|RGB|PCX|FITS|PM)' xv qiv
  101. complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview
  102. complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' xdvi
  103. complete -f -X '!*.@(dvi|DVI)?(.@(gz|Z|bz2))' kdvi
  104. complete -f -X '!*.@(dvi|DVI)' dvips dviselect dvitype dvipdf advi dvipdfm dvipdfmx
  105. complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf
  106. complete -f -X '!*.@(?(e)ps|?(E)PS|pdf|PDF)' kpdf
  107. complete -f -X '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2)|cb(r|z)|CB(R|Z)|djv?(u)|DJV?(U)|dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX)' evince
  108. complete -f -X '!*.@(?(e)ps|?(E)PS)' ps2pdf
  109. complete -f -X '!*.texi*' makeinfo texi2html
  110. complete -f -X '!*.@(?(la)tex|?(LA)TEX|texi|TEXI|dtx|DTX|ins|INS)' tex latex slitex jadetex pdfjadetex pdftex pdflatex texi2dvi
  111. complete -f -X '!*.@(mp3|MP3)' mpg123 mpg321 madplay
  112. complete -f -X '!*.@(mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp3|MP3|m4[pv]|M4[PV]|ogg|OGG|ogm|OGM|mp4|MP4|wav|WAV|asx|ASX|mng|MNG|srt)' xine aaxine fbxine kaffeine
  113. complete -f -X '!*.@(avi|asf|wmv)' aviplay
  114. complete -f -X '!*.@(rm?(j)|ra?(m)|smi?(l))' realplay
  115. complete -f -X '!*.@(mpg|mpeg|avi|mov|qt)' xanim
  116. complete -f -X '!*.@(ogg|OGG|m3u|flac|spx)' ogg123
  117. complete -f -X '!*.@(mp3|MP3|ogg|OGG|pls|m3u)' gqmpeg freeamp
  118. complete -f -X '!*.fig' xfig
  119. complete -f -X '!*.@(mid?(i)|MID?(I)|cmf|CMF)' playmidi
  120. complete -f -X '!*.@(mid?(i)|MID?(I)|rmi|RMI|rcp|RCP|[gr]36|[GR]36|g18|G18|mod|MOD|xm|XM|it|IT|x3m|X3M)' timidity
  121. complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' vi vim gvim rvim view rview rgvim rgview gview
  122. complete -f -X '*.@(o|so|so.!(conf)|a|rpm|gif|GIF|jp?(e)g|JP?(E)G|mp3|MP3|mp?(e)g|MPG|avi|AVI|asf|ASF|ogg|OGG|class|CLASS)' emacs
  123. complete -f -X '!*.@(exe|EXE|com|COM|scr|SCR|exe.so)' wine
  124. complete -f -X '!*.@(zip|ZIP|z|Z|gz|GZ|tgz|TGZ)' bzme
  125. complete -f -X '!*.@(?([xX]|[sS])[hH][tT][mM]?([lL]))' netscape mozilla lynx opera galeon curl dillo elinks amaya
  126. complete -f -X '!*.@(sxw|stw|sxg|sgl|doc|dot|rtf|txt|htm|html|odt|ott|odm)' oowriter
  127. complete -f -X '!*.@(sxi|sti|pps|ppt|pot|odp|otp)' ooimpress
  128. complete -f -X '!*.@(sxc|stc|xls|xlw|xlt|csv|ods|ots)' oocalc
  129. complete -f -X '!*.@(sxd|std|sda|sdd|odg|otg)' oodraw
  130. complete -f -X '!*.@(sxm|smf|mml|odf)' oomath
  131. complete -f -X '!*.odb' oobase
  132. complete -f -X '!*.rpm' rpm2cpio
  133. # FINISH exclude -- do not remove this line
  134.  
  135. # start of section containing compspecs that can be handled within bash
  136.  
  137. # user commands see only users
  138. complete -u su usermod userdel passwd chage write chfn groups slay w sux
  139.  
  140. # group commands see only groups
  141. [ -n "$bash205" ] && complete -g groupmod groupdel newgrp 2>/dev/null
  142.  
  143. # bg completes with stopped jobs
  144. complete -A stopped -P '"%' -S '"' bg
  145.  
  146. # other job commands
  147. complete -j -P '"%' -S '"' fg jobs disown
  148.  
  149. # readonly and unset complete with shell variables
  150. complete -v readonly unset
  151.  
  152. # set completes with set options
  153. complete -A setopt set
  154.  
  155. # shopt completes with shopt options
  156. complete -A shopt shopt
  157.  
  158. # helptopics
  159. complete -A helptopic help
  160.  
  161. # unalias completes with aliases
  162. complete -a unalias
  163.  
  164. # bind completes with readline bindings (make this more intelligent)
  165. complete -A binding bind
  166.  
  167. # type and which complete on commands
  168. complete -c command type which
  169.  
  170. # builtin completes on builtins
  171. complete -b builtin
  172.  
  173. # start of section containing completion functions called by other functions
  174.  
  175. # This function checks whether we have a given program on the system.
  176. # No need for bulky functions in memory if we don't.
  177. #
  178. have()
  179. {
  180.     unset -v have
  181.     PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
  182.         have="yes"
  183. }
  184.  
  185. # use GNU sed if we have it, since its extensions are still used in our code
  186. #
  187. [ $UNAME != Linux ] && have gsed && alias sed=gsed
  188.  
  189. # This function checks whether a given readline variable
  190. # is `on'.
  191. #
  192. _rl_enabled()
  193. {
  194.     [[ "$( bind -v )" = *$1+([[:space:]])on* ]]
  195. }
  196.  
  197. # This function shell-quotes the argument
  198. quote()
  199. {
  200.     echo \'${1//\'/\'\\\'\'}\' #'# Help vim syntax highlighting
  201. }
  202.  
  203. # This function quotes the argument in a way so that readline dequoting 
  204. # results in the original argument
  205. quote_readline()
  206. {
  207.     local t="${1//\\/\\\\}"
  208.     echo \'${t//\'/\'\\\'\'}\' #'# Help vim syntax highlighting
  209. }
  210.  
  211. # This function shell-dequotes the argument
  212. dequote()
  213. {
  214.     eval echo "$1"
  215. }
  216.  
  217. # Get the word to complete
  218. # This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases
  219. # where the user is completing in the middle of a word.
  220. # (For example, if the line is "ls foobar",
  221. # and the cursor is here -------->   ^
  222. # it will complete just "foo", not "foobar", which is what the user wants.)
  223. #
  224. #
  225. # Accepts an optional parameter indicating which characters out of
  226. # $COMP_WORDBREAKS should NOT be considered word breaks. This is useful
  227. # for things like scp where we want to return host:path and not only path.
  228. _get_cword()
  229. {
  230.     if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
  231.         echo "${COMP_WORDS[COMP_CWORD]}"
  232.     else
  233.         local i
  234.         local cur="$COMP_LINE"
  235.         local index="$COMP_POINT"
  236.         for (( i = 0; i <= COMP_CWORD; ++i )); do
  237.             while [[ "${#cur}" -ge ${#COMP_WORDS[i]} ]] && [[ "${cur:0:${#COMP_WORDS[i]}}" != "${COMP_WORDS[i]}" ]]; do
  238.                 cur="${cur:1}"
  239.                 index="$(( index - 1 ))"
  240.             done
  241.             if [[ "$i" -lt "$COMP_CWORD" ]]; then
  242.                 local old_size="${#cur}"
  243.                 cur="${cur#${COMP_WORDS[i]}}"
  244.                 local new_size="${#cur}"
  245.                 index="$(( index - old_size + new_size ))"
  246.             fi
  247.         done
  248.         
  249.         if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then
  250.             # We messed up! At least return the whole word so things 
  251.             # keep working
  252.             echo "${COMP_WORDS[COMP_CWORD]}"
  253.         else
  254.             echo "${cur:0:$index}"
  255.         fi
  256.     fi
  257. }
  258.  
  259. # This function performs file and directory completion. It's better than
  260. # simply using 'compgen -f', because it honours spaces in filenames.
  261. # If passed -d, it completes only on directories. If passed anything else,
  262. # it's assumed to be a file glob to complete on.
  263. #
  264. _filedir()
  265. {
  266.     local IFS=$'\t\n' xspec
  267.  
  268.     _expand || return 0
  269.  
  270.     local toks=( ) tmp
  271.     while read -r tmp; do
  272.         [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
  273.     done < <( compgen -d -- "$(quote_readline "$cur")" )
  274.     
  275.     if [[ "$1" != -d ]]; then
  276.         xspec=${1:+"!*.$1"}
  277.         while read -r tmp; do
  278.             [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
  279.         done < <( compgen -f -X "$xspec" -- "$(quote_readline "$cur")" )
  280.     fi
  281.  
  282.     COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
  283. }
  284.  
  285. # This function completes on signal names
  286. #
  287. _signals()
  288. {
  289.     local i
  290.  
  291.     # standard signal completion is rather braindead, so we need
  292.     # to hack around to get what we want here, which is to
  293.     # complete on a dash, followed by the signal name minus
  294.     # the SIG prefix
  295.     COMPREPLY=( $( compgen -A signal SIG${cur#-} ))
  296.     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  297.         COMPREPLY[i]=-${COMPREPLY[i]#SIG}
  298.     done
  299. }
  300.  
  301. # This function completes on configured network interfaces
  302. #
  303. _configured_interfaces()
  304. {
  305.     if [ -f /etc/debian_version ]; then
  306.         # Debian system
  307.         COMPREPLY=( $( sed -ne 's|^iface \([^ ]\+\).*$|\1|p' \
  308.                    /etc/network/interfaces ) )
  309.     elif [ -f /etc/SuSE-release ]; then
  310.         # SuSE system
  311.         COMPREPLY=( $( command ls \
  312.             /etc/sysconfig/network/ifcfg-* | \
  313.             sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
  314.     elif [ -f /etc/pld-release ]; then
  315.         # PLD Linux
  316.         COMPREPLY=( $( command ls -B \
  317.             /etc/sysconfig/interfaces | \
  318.             sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
  319.     else
  320.         # Assume Red Hat
  321.         COMPREPLY=( $( command ls \
  322.             /etc/sysconfig/network-scripts/ifcfg-* | \
  323.             sed -ne 's|.*ifcfg-\('$cur'.*\)|\1|p' ) )
  324.     fi
  325. }
  326.  
  327. # This function completes on all available network interfaces
  328. # -a: restrict to active interfaces only
  329. # -w: restrict to wireless interfaces only
  330. #
  331. _available_interfaces()
  332. {
  333.     local cmd
  334.  
  335.     if [ "${1:-}" = -w ]; then
  336.         cmd="iwconfig"
  337.     elif [ "${1:-}" = -a ]; then
  338.         cmd="ifconfig"
  339.     else
  340.         cmd="ifconfig -a"
  341.     fi
  342.  
  343.     COMPREPLY=( $( eval $cmd 2>/dev/null | \
  344.         sed -ne 's|^\('$cur'[^[:space:][:punct:]]\{1,\}\).*$|\1|p') )
  345. }
  346.  
  347. # This function expands tildes in pathnames
  348. #
  349. _expand()
  350. {
  351.     # FIXME: Why was this here?
  352.     #[ "$cur" != "${cur%\\}" ] && cur="$cur\\"
  353.  
  354.     # expand ~username type directory specifications
  355.     if [[ "$cur" == \~*/* ]]; then
  356.         eval cur=$cur
  357.     elif [[ "$cur" == \~* ]]; then
  358.         cur=${cur#\~}
  359.         COMPREPLY=( $( compgen -P '~' -u $cur ) )
  360.         return ${#COMPREPLY[@]}
  361.     fi
  362. }
  363.  
  364. # This function completes on process IDs.
  365. # AIX and Solaris ps prefers X/Open syntax.
  366. [ $UNAME = SunOS -o $UNAME = AIX ] &&
  367. _pids()
  368. {
  369.     COMPREPLY=( $( compgen -W '$( command ps -efo pid | sed 1d )' -- $cur ))
  370. } ||
  371. _pids()
  372. {
  373.     COMPREPLY=( $( compgen -W '$( command ps axo pid | sed 1d )' -- $cur ) )
  374. }
  375.  
  376. # This function completes on process group IDs.
  377. # AIX and SunOS prefer X/Open, all else should be BSD.
  378. [ $UNAME = SunOS -o $UNAME = AIX ] &&
  379. _pgids()
  380. {
  381.     COMPREPLY=( $( compgen -W '$( command ps -efo pgid | sed 1d )' -- $cur ))
  382. } ||
  383. _pgids()
  384. {
  385.     COMPREPLY=( $( compgen -W '$( command ps axo pgid | sed 1d )' -- $cur ))
  386. }
  387.  
  388. # This function completes on user IDs
  389. #
  390. _uids()
  391. {
  392.     if type getent &>/dev/null; then
  393.         COMPREPLY=( $( getent passwd | \
  394.                 awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
  395.     elif type perl &>/dev/null; then
  396.         COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($uid) = (getpwent)[2]) { print $uid . "\n" }'"'"' )' -- $cur ) )
  397.     else
  398.         # make do with /etc/passwd
  399.         COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
  400.                 /etc/passwd ) )
  401.     fi
  402. }
  403.  
  404. # This function completes on group IDs
  405. #
  406. _gids()
  407. {
  408.     if type getent &>/dev/null; then
  409.         COMPREPLY=( $( getent group | \
  410.                 awk -F: '{if ($3 ~ /^'$cur'/) print $3}' ) )
  411.     elif type perl &>/dev/null; then
  412.         COMPREPLY=( $( compgen -W '$( perl -e '"'"'while (($gid) = (getgrent)[2]) { print $gid . "\n" }'"'"' )' -- $cur ) )
  413.     else
  414.         # make do with /etc/group
  415.         COMPREPLY=( $( awk 'BEGIN {FS=":"} {if ($3 ~ /^'$cur'/) print $3}'\
  416.                 /etc/group ) )
  417.     fi
  418. }
  419.  
  420. # This function completes on services
  421. #
  422. _services()
  423. {
  424.     local sysvdir famdir
  425.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
  426.     famdir=/etc/xinetd.d
  427.     COMPREPLY=( $( builtin echo $sysvdir/!(*.rpmsave|*.rpmorig|*~|functions)) )
  428.  
  429.     if [ -d $famdir ]; then
  430.         COMPREPLY=( "${COMPREPLY[@]}" $( builtin echo $famdir/!(*.rpmsave|*.rpmorig|*~)) )
  431.     fi
  432.  
  433.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- $cur ) )
  434. }
  435.  
  436. # This function complete on modules
  437. #
  438. _modules()
  439. {
  440.     local modpath
  441.     modpath=/lib/modules/$1
  442.     COMPREPLY=( $( command ls -R $modpath | \
  443.             sed -ne 's/^\('$cur'.*\)\.k\?o\(\|.gz\)$/\1/p') )
  444. }
  445.  
  446. # This function completes on installed modules
  447. #
  448. _installed_modules()
  449. {
  450.     COMPREPLY=( $( compgen -W "$( /sbin/lsmod | \
  451.                   awk '{if (NR != 1) print $1}' )" -- $1 ) )
  452. }
  453.  
  454. # this function complete on user:group format
  455. #
  456. _usergroup()
  457. {
  458.     local IFS=$'\n'
  459.     cur=${cur//\\\\ / }
  460.     if [[ $cur = *@(\\:|.)* ]] && [ -n "$bash205" ]; then
  461.         user=${cur%%*([^:.])}
  462.         COMPREPLY=( $(compgen -P ${user/\\\\} -g -- ${cur##*[.:]}) )
  463.     elif [[ $cur = *:* ]] && [ -n "$bash205" ]; then
  464.         COMPREPLY=( $( compgen -g -- ${cur##*[.:]} ) )
  465.     else
  466.         COMPREPLY=( $( compgen -S : -u -- $cur ) )
  467.     fi
  468. }
  469.  
  470. # this function count the number of mandatory args
  471. #
  472. _count_args()
  473. {
  474.     args=1
  475.     for (( i=1; i < COMP_CWORD; i++ )); do
  476.         if [[ "${COMP_WORDS[i]}" != -* ]]; then
  477.             args=$(($args+1))
  478.         fi
  479.     done
  480. }
  481.  
  482. # start of section containing completion functions for bash built-ins
  483.  
  484. # bash alias completion
  485. #
  486. _alias()
  487. {
  488.     local cur
  489.  
  490.     COMPREPLY=()
  491.     cur=${COMP_WORDS[$COMP_CWORD]}
  492.  
  493.     case "$COMP_LINE" in
  494.     *[^=])
  495.         COMPREPLY=( $( compgen -A alias -S '=' -- $cur ) )
  496.         ;;
  497.     *=)
  498.         COMPREPLY=( "$( alias ${cur%=} 2>/dev/null | \
  499.                  sed -e 's|^alias '$cur'\(.*\)$|\1|' )" )
  500.         ;;
  501.     esac
  502. }
  503. complete -F _alias $nospace alias
  504.  
  505. # bash export completion
  506. #
  507. _export()
  508. {
  509.     local cur
  510.  
  511.     COMPREPLY=()
  512.     cur=`_get_cword`
  513.  
  514.     case "$COMP_LINE" in
  515.     *=\$*)
  516.         COMPREPLY=( $( compgen -v -P '$' -- ${cur#*=\$} ) )
  517.         ;;
  518.     *[^=])
  519.         COMPREPLY=( $( compgen -v -S '=' -- $cur ) )
  520.         ;;
  521.     *=)
  522.         COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
  523.             ( echo -n \'
  524.               sed -e 's/'\''/'\''\\\'\'''\''/g'
  525.               echo -n \' ) )" )
  526.         ;;
  527.     esac
  528. }
  529. complete -F _export $default $nospace export
  530.  
  531. # bash shell function completion
  532. #
  533. _function()
  534. {
  535.     local cur prev
  536.  
  537.     COMPREPLY=()
  538.     cur=`_get_cword`
  539.     prev=${COMP_WORDS[COMP_CWORD-1]}
  540.  
  541.     if [[ $1 == @(declare|typeset) ]]; then
  542.         if [ "$prev" = -f ]; then
  543.             COMPREPLY=( $( compgen -A function -- $cur ) )
  544.         elif [[ "$cur" == -* ]]; then
  545.             COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- \
  546.                        $cur ) )
  547.         fi
  548.     elif [ $COMP_CWORD -eq 1 ]; then
  549.         COMPREPLY=( $( compgen -A function -- $cur ) )
  550.     else
  551.         COMPREPLY=( "() $( type -- ${COMP_WORDS[1]} | sed -e 1,2d )" )
  552.     fi
  553. }
  554. complete -F _function function declare typeset
  555.  
  556. # bash complete completion
  557. #
  558. _complete()
  559. {
  560.     local cur prev options
  561.  
  562.     COMPREPLY=()
  563.     cur=`_get_cword`
  564.     prev=${COMP_WORDS[COMP_CWORD-1]}
  565.  
  566.     case $prev in
  567.         -o)
  568.             options="default dirnames filenames"
  569.             [ -n "$bash205b" ] && options="$options nospace"
  570.             [ -n "$bash3" ] && options="$options bashdefault plusdirs"
  571.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  572.             return 0
  573.             ;;
  574.  
  575.         -A)
  576.             COMPREPLY=( $( compgen -W 'alias arrayvar binding \
  577.                 builtin command directory disabled enabled \
  578.                 export file function group helptopic hostname \
  579.                 job keyword running service setopt shopt \
  580.                 signal stopped user variable' -- $cur ) )
  581.             return 0
  582.             ;;
  583.  
  584.         -C)
  585.             COMPREPLY=( $( compgen -A command -- $cur ) )
  586.             return 0
  587.             ;;
  588.         -F)
  589.             COMPREPLY=( $( compgen -A function -- $cur ) )
  590.             return 0
  591.             ;;
  592.         -@(p|r))
  593.             COMPREPLY=( $( complete -p | sed -e 's|.* ||' | \
  594.                     grep "^$cur" ) )
  595.             return 0
  596.             ;;
  597.  
  598.     esac
  599.  
  600.     if [[ "$cur" == -* ]]; then
  601.         # relevant options completion
  602.         options="-a -b -c -d -e -f -g -j -k -s -v -u -A -G -W -P -S -X -F -C"
  603.         [ -n "$bash205" ] && options="$options -o"
  604.         COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  605.     else
  606.         COMPREPLY=( $( compgen -A command -- $cur ) )
  607.     fi
  608. }
  609. complete -F _complete complete
  610.  
  611. # start of section containing completion functions for external programs
  612.  
  613. # a little help for FreeBSD ports users
  614. [ $UNAME = FreeBSD ] && complete -W 'index search fetch fetch-list \
  615.     extract patch configure build install reinstall \
  616.     deinstall clean clean-depends kernel buildworld' make
  617.  
  618. # This completes on a list of all available service scripts for the
  619. # 'service' command and/or the SysV init.d directory, followed by
  620. # that script's available commands
  621. #
  622. { have service || [ -d /etc/init.d/ ]; } &&
  623. _service()
  624. {
  625.     local cur sysvdir
  626.  
  627.     COMPREPLY=()
  628.     prev=${COMP_WORDS[COMP_CWORD-1]}
  629.     cur=`_get_cword`
  630.  
  631.     # don't complete for things like killall, ssh and mysql if it's
  632.     # the standalone command, rather than the init script
  633.     [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0
  634.  
  635.     # don't complete past 2nd token
  636.     [ $COMP_CWORD -gt 2 ] && return 0
  637.  
  638.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  639.                 || sysvdir=/etc/init.d
  640.  
  641.     if [[ $COMP_CWORD -eq 1 ]] && [[ $prev == "service" ]]; then
  642.         _services
  643.     else
  644.         COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
  645.                 s/^.*Usage.*{\(.*\)}.*$/\1/p" \
  646.                 $sysvdir/${prev##*/} 2>/dev/null`' -- $cur ) )
  647.     fi
  648.  
  649.     return 0
  650. } &&
  651. complete -F _service service
  652. [ -d /etc/init.d/ ] && complete -F _service $default \
  653.     $(for i in /etc/init.d/*; do echo ${i##*/}; done)
  654.  
  655. # chown(1) completion
  656. #
  657. _chown()
  658. {
  659.     local cur
  660.     cur=`_get_cword`
  661.  
  662.     # options completion
  663.     if [[ "$cur" == -* ]]; then
  664.         COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
  665.         --dereference --no-dereference --from= --silent --quiet \
  666.         --reference= --recursive --verbose --help --version' -- $cur ) )
  667.     else
  668.         _count_args
  669.  
  670.         case $args in
  671.             1)
  672.                 _usergroup
  673.                 ;;
  674.             *)
  675.                 _filedir
  676.                 ;;
  677.         esac
  678.     fi
  679. }
  680. complete -F _chown $filenames chown
  681.  
  682. # chgrp(1) completion
  683. #
  684. _chgrp()
  685. {
  686.     local cur prev
  687.  
  688.     COMPREPLY=()
  689.     cur=`_get_cword`
  690.     cur=${cur//\\\\/}
  691.     prev=${COMP_WORDS[COMP_CWORD-1]}
  692.  
  693.     # options completion
  694.     if [[ "$cur" == -* ]]; then
  695.         COMPREPLY=( $( compgen -W '-c -h -f -R -v --changes \
  696.         --dereference --no-dereference --silent --quiet \
  697.         --reference= --recursive --verbose --help --version' -- $cur ) )
  698.         return 0
  699.     fi
  700.  
  701.     # first parameter on line or first since an option?
  702.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]] || \
  703.        [[ "$prev" == -* ]] && [ -n "$bash205" ]; then
  704.         local IFS=$'\n'
  705.         COMPREPLY=( $( compgen -g $cur 2>/dev/null ) )
  706.     else
  707.         _filedir || return 0
  708.     fi
  709.  
  710.     return 0
  711. }
  712. complete -F _chgrp $filenames chgrp
  713.  
  714. # umount(8) completion. This relies on the mount point being the third
  715. # space-delimited field in the output of mount(8)
  716. #
  717. _umount()
  718. {
  719.     local cur IFS=$'\n'
  720.  
  721.     COMPREPLY=()
  722.     cur=`_get_cword`
  723.  
  724.     local IFS=$'\n'
  725.     COMPREPLY=( $( compgen -W '$( mount | cut -d" " -f 3 )' -- $cur ) )
  726.  
  727.     return 0
  728. }
  729. complete -F _umount $dirnames umount
  730.  
  731. # mount(8) completion. This will pull a list of possible mounts out of
  732. # /etc/{,v}fstab, unless the word being completed contains a ':', which
  733. # would indicate the specification of an NFS server. In that case, we
  734. # query the server for a list of all available exports and complete on
  735. # that instead.
  736. #
  737. _mount()
  738. {
  739.     local cur i sm host
  740.  
  741.     COMPREPLY=()
  742.     cur=`_get_cword`
  743.     [[ "$cur" == \\ ]] && cur="/"
  744.  
  745.     for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done
  746.  
  747.     if [ -n "$sm" ] && [[ "$cur" == *:* ]]; then
  748.         COMPREPLY=( $( $sm -e ${cur%%:*} | sed 1d | \
  749.                    grep ^${cur#*:} | awk '{print $1}' ) )
  750.     elif [[ "$cur" == //* ]]; then
  751.         host=${cur#//}
  752.         host=${host%%/*}
  753.         if [ -n "$host" ]; then
  754.             COMPREPLY=( $( compgen -W "$( echo $( smbclient -d 0 -NL $host 2>/dev/null|
  755.             sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
  756.             sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|//'$host'/\1|p' ) )" -- "$cur" ) )
  757.         fi
  758.     elif [ -r /etc/vfstab ]; then
  759.         # Solaris
  760.         COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
  761.                 /etc/vfstab | grep "^$cur" ) )
  762.     elif [ ! -e /etc/fstab ]; then
  763.         # probably Cygwin
  764.         COMPREPLY=( $( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' \
  765.                  | grep "^$cur" ) )
  766.     else
  767.         # probably Linux
  768.         COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \
  769.                 /etc/fstab | grep "^$cur" ) )
  770.     fi
  771.  
  772.     return 0
  773. }
  774. complete -F _mount $default $filenames mount
  775.  
  776. # Linux rmmod(8) completion. This completes on a list of all currently
  777. # installed kernel modules.
  778. #
  779. have rmmod && {
  780. _rmmod()
  781. {
  782.     local cur
  783.  
  784.     COMPREPLY=()
  785.     cur=`_get_cword`
  786.  
  787.     _installed_modules "$cur"
  788.     return 0
  789. }
  790. complete -F _rmmod rmmod
  791.  
  792. # Linux insmod(8), modprobe(8) and modinfo(8) completion. This completes on a
  793. # list of all available modules for the version of the kernel currently
  794. # running.
  795. #
  796. _insmod()
  797. {
  798.     local cur prev modpath
  799.  
  800.     COMPREPLY=()
  801.     cur=`_get_cword`
  802.     prev=${COMP_WORDS[COMP_CWORD-1]}
  803.  
  804.     # behave like lsmod for modprobe -r
  805.     if [ $1 = "modprobe" ] &&
  806.        [ "${COMP_WORDS[1]}" = "-r" ]; then
  807.         _installed_modules "$cur"
  808.         return 0
  809.     fi
  810.  
  811.     # do filename completion if we're giving a path to a module
  812.     if [[ "$cur" == */* ]]; then
  813.         _filedir '@(?(k)o?(.gz))'
  814.         return 0
  815.     fi
  816.  
  817.     if [ $COMP_CWORD -gt 1 ] &&
  818.        [[ "${COMP_WORDS[COMP_CWORD-1]}" != -* ]]; then
  819.         # do module parameter completion
  820.         COMPREPLY=( $( /sbin/modinfo -p ${COMP_WORDS[1]} 2>/dev/null | \
  821.                awk '{if ($1 ~ /^parm:/ && $2 ~ /^'$cur'/) { print $2 } \
  822.             else if ($1 !~ /:/ && $1 ~ /^'$cur'/) { print $1 }}' ) )
  823.     else
  824.         _modules $(uname -r)
  825.     fi
  826.  
  827.     return 0
  828. }
  829. complete -F _insmod $filenames insmod modprobe modinfo
  830. }
  831.  
  832. # man(1) completion
  833. #
  834. [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
  835.   -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
  836.   -o $UNAME = OpenBSD ] &&
  837. _man()
  838. {
  839.     local cur prev sect manpath UNAME
  840.  
  841.     COMPREPLY=()
  842.     cur=`_get_cword`
  843.     prev=${COMP_WORDS[COMP_CWORD-1]}
  844.  
  845.     _expand || return 0
  846.  
  847.     # default completion if parameter contains /
  848.     if [[ "$cur" == */* ]]; then
  849.         _filedir
  850.         return 0
  851.     fi
  852.  
  853.     UNAME=$( uname -s )
  854.     # strip OS type and version under Cygwin
  855.     UNAME=${UNAME/CYGWIN_*/Cygwin}
  856.     if [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = FreeBSD \
  857.          -o $UNAME = Cygwin ]; then
  858.         manpath=$( manpath 2>/dev/null || command man --path )
  859.     else
  860.         manpath=$MANPATH
  861.     fi
  862.  
  863.     if [ -z "$manpath" ]; then
  864.         COMPREPLY=( $( compgen -c -- $cur ) )
  865.         return 0
  866.     fi
  867.  
  868.     # determine manual section to search
  869.     [[ "$prev" == [0-9ln] ]] && sect=$prev || sect='*'
  870.  
  871.     manpath=$manpath:
  872.     if [ -n "$cur" ]; then
  873.         manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
  874.     else
  875.         manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
  876.     fi
  877.  
  878.     # redirect stderr for when path doesn't exist
  879.     COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
  880.     # weed out directory path names and paths to man pages
  881.     COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
  882.     # strip suffix from man pages
  883.     COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
  884.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
  885.  
  886.     [[ "$prev" != [0-9ln] ]] && _filedir '[0-9ln]'
  887.  
  888.     return 0
  889. }
  890. [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Darwin \
  891.   -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
  892.   -o $UNAME = OpenBSD ] && \
  893. complete -F _man $filenames man apropos whatis
  894.  
  895. # renice(8) completion
  896. #
  897. _renice()
  898. {
  899.     local command cur curopt i
  900.  
  901.     COMPREPLY=()
  902.     cur=`_get_cword`
  903.     command=$1
  904.  
  905.     i=0
  906.     # walk back through command line and find last option
  907.     while [ $i -le $COMP_CWORD -a ${#COMPREPLY[@]} -eq 0 ]; do
  908.         curopt=${COMP_WORDS[COMP_CWORD-$i]}
  909.         case "$curopt" in
  910.         -u)
  911.             COMPREPLY=( $( compgen -u -- $cur ) )
  912.             ;;
  913.         -g)
  914.             _pgids
  915.             ;;
  916.         -p|$command)
  917.             _pids
  918.             ;;
  919.         esac
  920.         i=$(( ++i ))
  921.     done
  922. }
  923. complete -F _renice renice
  924.  
  925. # kill(1) completion
  926. #
  927. _kill()
  928. {
  929.     local cur
  930.  
  931.     COMPREPLY=()
  932.     cur=`_get_cword`
  933.  
  934.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
  935.         # return list of available signals
  936.         _signals
  937.     else
  938.         # return list of available PIDs
  939.         _pids
  940.     fi
  941. }
  942. complete -F _kill kill
  943.  
  944. # Linux and FreeBSD killall(1) completion.
  945. #
  946. [ $UNAME = Linux -o $UNAME = FreeBSD ] &&
  947. _killall()
  948. {
  949.     local cur
  950.  
  951.     COMPREPLY=()
  952.     cur=`_get_cword`
  953.  
  954.     if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
  955.         _signals
  956.     else
  957.         COMPREPLY=( $( compgen -W '$( command ps axo command | \
  958.                   sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
  959.                   sed -e "s/.*\///" )' -- $cur ) )
  960.     fi
  961.  
  962.     return 0
  963. }
  964. [ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _killall killall pkill
  965.  
  966. # Linux and FreeBSD pgrep(1) completion.
  967. #
  968. [ $UNAME = Linux -o $UNAME = FreeBSD ] &&
  969. _pgrep()
  970. {
  971.     local cur
  972.  
  973.     COMPREPLY=()
  974.     cur=`_get_cword`
  975.  
  976.     COMPREPLY=( $( compgen -W '$( command ps axo command | \
  977.               sed -ne "1d; s/^\[\?\([^-][^] ]*\).*$/\1/p" | \
  978.               sed -e "s/.*\///" )' -- $cur ) )
  979.  
  980.     return 0
  981. }
  982. [ $UNAME = Linux -o $UNAME = FreeBSD ] && complete -F _pgrep pgrep
  983. # Linux pidof(8) completion.
  984. [ $UNAME = Linux ] && complete -F _pgrep pidof
  985.  
  986. # GNU find(1) completion. This makes heavy use of ksh style extended
  987. # globs and contains Linux specific code for completing the parameter
  988. # to the -fstype option.
  989. #
  990. _find()
  991. {
  992.     local cur prev i exprfound onlyonce
  993.  
  994.     COMPREPLY=()
  995.     cur=`_get_cword`
  996.     prev=${COMP_WORDS[COMP_CWORD-1]}
  997.  
  998.     case "$prev" in
  999.     -@(max|min)depth)
  1000.         COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- $cur ) )
  1001.         return 0
  1002.         ;;
  1003.     -?(a|c)newer|-fls|-fprint?(0|f)|-?(i)?(l)name|-?(i)wholename)
  1004.         _filedir
  1005.         return 0
  1006.         ;;
  1007.     -fstype)
  1008.         # this is highly non-portable
  1009.         [ -e /proc/filesystems ] &&
  1010.         COMPREPLY=( $( cut -d$'\t' -f 2 /proc/filesystems | \
  1011.                 grep "^$cur" ) )
  1012.         return 0
  1013.         ;;
  1014.     -gid)
  1015.         _gids
  1016.         return 0
  1017.         ;;
  1018.     -group)
  1019.         if [ -n "$bash205" ]; then
  1020.             COMPREPLY=( $( compgen -g -- $cur 2>/dev/null) )
  1021.         fi
  1022.         return 0
  1023.         ;;
  1024.     -?(x)type)
  1025.         COMPREPLY=( $( compgen -W 'b c d p f l s' -- $cur ) )
  1026.         return 0
  1027.         ;;
  1028.     -uid)
  1029.         _uids
  1030.         return 0
  1031.         ;;
  1032.     -user)
  1033.         COMPREPLY=( $( compgen -u -- $cur ) )
  1034.         return 0
  1035.         ;;
  1036.     -exec|-ok)
  1037.         COMP_WORDS=(COMP_WORDS[0] $cur)
  1038.         COMP_CWORD=1
  1039.         _command
  1040.         return 0
  1041.         ;;
  1042.     -[acm]min|-[acm]time|-?(i)?(l)name|-inum|-?(i)path|-?(i)regex| \
  1043.     -links|-perm|-size|-used|-printf)
  1044.         # do nothing, just wait for a parameter to be given
  1045.         return 0
  1046.         ;;
  1047.     esac
  1048.  
  1049.     _expand || return 0
  1050.  
  1051.     # set exprfound to 1 if there is already an expression present
  1052.     for i in ${COMP_WORDS[@]}; do
  1053.         [[ "$i" = [-\(\),\!]* ]] && exprfound=1 && break
  1054.     done
  1055.  
  1056.     # handle case where first parameter is not a dash option
  1057.     if [ "$exprfound" != 1 ] && [[ "$cur" != [-\(\),\!]* ]]; then
  1058.         _filedir -d
  1059.         return 0
  1060.     fi
  1061.  
  1062.     # complete using basic options
  1063.     COMPREPLY=( $( compgen -W '-daystart -depth -follow -help -maxdepth \
  1064.             -mindepth -mount -noleaf -version -xdev -amin -anewer \
  1065.             -atime -cmin -cnewer -ctime -empty -false -fstype \
  1066.             -gid -group -ilname -iname -inum -ipath -iregex \
  1067.             -wholename \
  1068.             -links -lname -mmin -mtime -name -newer -nouser \
  1069.             -nogroup -perm -regex -size -true -type -uid -used \
  1070.             -user -xtype -exec -fls -fprint -fprint0 -fprintf -ok \
  1071.             -print -print0 -printf -prune -ls' -- $cur ) )
  1072.  
  1073.     # this removes any options from the list of completions that have
  1074.     # already been specified somewhere on the command line, as long as
  1075.     # these options can only be used once (in a word, "options", in
  1076.     # opposition to "tests" and "actions", as in the find(1) manpage).
  1077.     onlyonce=' -daystart -depth -follow -help -maxdepth -mindepth -mount \
  1078.            -noleaf -version -xdev '
  1079.     COMPREPLY=( $( echo "${COMP_WORDS[@]}" | \
  1080.                (while read -d ' ' i; do
  1081.                 [ "$i" == "" ] ||
  1082.                 [ "${onlyonce/ ${i%% *} / }" == "$onlyonce" ] &&
  1083.                 continue
  1084.                 # flatten array with spaces on either side,
  1085.                 # otherwise we cannot grep on word boundaries of
  1086.                 # first and last word
  1087.                 COMPREPLY=" ${COMPREPLY[@]} "
  1088.                 # remove word from list of completions
  1089.                 COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
  1090.             done
  1091.             echo "${COMPREPLY[@]}")
  1092.           ) )
  1093.  
  1094.     _filedir
  1095.  
  1096.     return 0
  1097. }
  1098. complete -F _find $filenames find
  1099.  
  1100. # Linux iwconfig(8) completion
  1101. #
  1102. [ $UNAME = Linux ] && have iwconfig &&
  1103. _iwconfig()
  1104. {
  1105.     local cur prev
  1106.  
  1107.     COMPREPLY=()
  1108.     cur=`_get_cword`
  1109.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1110.  
  1111.     case $prev in
  1112.         mode)
  1113.             COMPREPLY=( $( compgen -W 'managed ad-hoc master \
  1114.                 repeater secondary monitor' -- $cur ) )
  1115.             return 0
  1116.             ;;
  1117.         essid)
  1118.             COMPREPLY=( $( compgen -W 'on off any' -- $cur ) )
  1119.             if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
  1120.                 COMPREPLY=( "${COMPREPLY[@]}" \
  1121.                     $( iwlist ${COMP_WORDS[1]} scan | \
  1122.                     awk -F '"' '/ESSID/ {print $2}' | \
  1123.                     grep "^$cur" ))
  1124.             fi
  1125.             return 0
  1126.             ;;
  1127.         nwid)
  1128.             COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  1129.             return 0
  1130.             ;;
  1131.         channel)
  1132.             COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \
  1133.                 awk '/^[[:space:]]*Channel/ {print $2}' | \
  1134.                 grep "^$cur" ) )
  1135.             return 0
  1136.             ;;
  1137.  
  1138.         freq)
  1139.             COMPREPLY=( $( iwlist ${COMP_WORDS[1]} channel | \
  1140.                 awk '/^[[:space:]]*Channel/ {print $4"G"}' | \
  1141.                 grep "^$cur" ) )
  1142.             return 0
  1143.             ;;
  1144.         ap)
  1145.             COMPREPLY=( $( compgen -W 'on off any' -- $cur ) )
  1146.             if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
  1147.                 COMPREPLY=( "${COMPREPLY[@]}" \
  1148.                     $( iwlist ${COMP_WORDS[1]} scan | \
  1149.                     awk -F ': ' '/Address/ {print $2}' | \
  1150.                     grep "^$cur" ) )
  1151.             fi
  1152.             return 0
  1153.             ;;
  1154.         rate)
  1155.             COMPREPLY=( $( compgen -W 'auto fixed' -- $cur ) )
  1156.             COMPREPLY=( "${COMPREPLY[@]}" \
  1157.                 $( iwlist ${COMP_WORDS[1]} rate | \
  1158.                 awk '/^[[:space:]]*[0-9]/ {print $1"M"}' | \
  1159.                 grep "^$cur" ) )
  1160.             return 0
  1161.             ;;
  1162.         rts)
  1163.             COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) )
  1164.             return 0
  1165.             ;;
  1166.         frag)
  1167.             COMPREPLY=( $( compgen -W 'auto fixed off' -- $cur ) )
  1168.             return 0
  1169.             ;;
  1170.         key)
  1171.             COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) )
  1172.             return 0
  1173.             ;;
  1174.         enc)
  1175.             COMPREPLY=( $( compgen -W 'off on open restricted' -- $cur ) )
  1176.             return 0
  1177.             ;;
  1178.         power)
  1179.             COMPREPLY=( $( compgen -W 'period timeout off on' -- $cur ) )
  1180.             return 0
  1181.             ;;
  1182.         txpower)
  1183.             COMPREPLY=( $( compgen -W 'off on auto' -- $cur ) )
  1184.             return 0
  1185.             ;;
  1186.         retry)
  1187.             COMPREPLY=( $( compgen -W 'limit lifetime' -- $cur ) )
  1188.             return 0
  1189.             ;;
  1190.     esac
  1191.  
  1192.     if [ $COMP_CWORD -eq 1 ]; then
  1193.         if [[ "$cur" == -* ]]; then
  1194.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
  1195.         else
  1196.             _available_interfaces -w
  1197.         fi
  1198.     else
  1199.         COMPREPLY=( $( compgen -W 'essid nwid mode freq channel sens mode \
  1200.             ap nick rate rts frag enc key power txpower commit' -- $cur ) )
  1201.     fi
  1202.  
  1203. } &&
  1204. complete -F _iwconfig iwconfig
  1205.  
  1206. # Linux iwlist(8) completion
  1207. #
  1208. [ $UNAME = Linux ] && have iwlist &&
  1209. _iwlist()
  1210. {
  1211.     local cur prev
  1212.  
  1213.     COMPREPLY=()
  1214.     cur=`_get_cword`
  1215.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1216.  
  1217.     if [ $COMP_CWORD -eq 1 ]; then
  1218.         if [[ "$cur" == -* ]]; then
  1219.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
  1220.         else
  1221.             _available_interfaces -w
  1222.         fi
  1223.     else
  1224.         COMPREPLY=( $( compgen -W 'scan scanning freq frequency \
  1225.             channel rate bit bitrate key enc encryption power \
  1226.             txpower retry ap accesspoint peers event' -- $cur ) )
  1227.     fi
  1228. } &&
  1229. complete -F _iwlist iwlist
  1230.  
  1231. # Linux iwspy(8) completion
  1232. #
  1233. [ $UNAME = Linux ] && have iwspy &&
  1234. _iwspy()
  1235. {
  1236.     local cur
  1237.  
  1238.     COMPREPLY=()
  1239.     cur=`_get_cword`
  1240.  
  1241.     if [ $COMP_CWORD -eq 1 ]; then
  1242.         if [[ "$cur" == -* ]]; then
  1243.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
  1244.         else
  1245.             _available_interfaces -w
  1246.         fi
  1247.     else
  1248.         COMPREPLY=( $( compgen -W 'setthr getthr off' -- $cur ) )
  1249.     fi
  1250. } &&
  1251. complete -F _iwspy iwspy
  1252.  
  1253. # Linux iwpriv(8) completion
  1254. #
  1255. [ $UNAME = Linux ] && have iwpriv &&
  1256. _iwpriv()
  1257. {
  1258.     local cur prev
  1259.  
  1260.     COMPREPLY=()
  1261.     cur=`_get_cword`
  1262.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1263.  
  1264.     case "$prev" in
  1265.         roam)
  1266.             COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  1267.             return 0
  1268.             ;;
  1269.         port)
  1270.             COMPREPLY=( $( compgen -W 'ad-hoc managed' -- $cur ) )
  1271.             return 0
  1272.             ;;
  1273.     esac
  1274.  
  1275.     if [ $COMP_CWORD -eq 1 ]; then
  1276.         if [[ "$cur" == -* ]]; then
  1277.             COMPREPLY=( $( compgen -W '--help --version' -- $cur ) )
  1278.         else
  1279.             _available_interfaces -w
  1280.         fi
  1281.     else
  1282.         COMPREPLY=( $( compgen -W '--all roam port' -- $cur ) )
  1283.     fi
  1284. } &&
  1285. complete -F _iwpriv iwpriv
  1286.  
  1287. # RedHat & Debian GNU/Linux if{up,down} completion
  1288. #
  1289. [ $UNAME = Linux ] && { have ifup || have ifdown; } &&
  1290. _ifupdown()
  1291. {
  1292.     local cur
  1293.  
  1294.     COMPREPLY=()
  1295.     cur=`_get_cword`
  1296.  
  1297.     if [ $COMP_CWORD -eq 1 ]; then
  1298.         _configured_interfaces
  1299.         COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") )
  1300.        fi
  1301.  
  1302.        return 0
  1303. } &&
  1304. complete -F _ifupdown ifup ifdown
  1305. [ $UNAME = Linux ] && have ifstatus && complete -F _ifupdown ifstatus
  1306.  
  1307. # Linux ipsec(8) completion (for FreeS/WAN)
  1308. #
  1309. [ $UNAME = Linux ] && have ipsec &&
  1310. _ipsec()
  1311. {
  1312.     local cur
  1313.  
  1314.     COMPREPLY=()
  1315.     cur=`_get_cword`
  1316.  
  1317.  
  1318.     if [ $COMP_CWORD -eq 1 ]; then
  1319.         COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look \
  1320.                        manual pluto ranbits rsasigkey \
  1321.                        setup showdefaults showhostkey spi \
  1322.                        spigrp tncfg whack' -- $cur ) )
  1323.         return 0
  1324.     fi
  1325.  
  1326.     case ${COMP_WORDS[1]} in
  1327.     auto)
  1328.         COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \
  1329.                        --replace --down --route --unroute \
  1330.                        --ready --status --rereadsecrets' \
  1331.                     -- $cur ) )
  1332.         ;;
  1333.     manual)
  1334.         COMPREPLY=( $( compgen -W '--up --down --route --unroute \
  1335.                        --union' -- $cur ) )
  1336.         ;;
  1337.     ranbits)
  1338.         COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \
  1339.                       -- $cur ) )
  1340.         ;;
  1341.     setup)
  1342.         COMPREPLY=( $( compgen -W '--start --stop --restart' -- $cur ) )
  1343.         ;;
  1344.  
  1345.     *)
  1346.         ;;
  1347.     esac
  1348.  
  1349.     return 0
  1350. } &&
  1351. complete -F _ipsec ipsec
  1352.  
  1353. # Postfix completion.
  1354. #
  1355. have postfix && {
  1356. # postfix(1)
  1357. #
  1358. _postfix()
  1359. {
  1360.     local cur prev
  1361.  
  1362.     cur=`_get_cword`
  1363.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1364.  
  1365.     if [[ $cur == '-' ]]; then
  1366.         COMPREPLY=(-c -D -v)
  1367.         return 0
  1368.     fi
  1369.     if [[ $prev == '-c' ]]; then
  1370.         _filedir -d
  1371.         return 0
  1372.     fi
  1373.     if [[ $prev == '-D' ]]; then
  1374.         COMPREPLY=( $( compgen -W 'start' -- "`_get_cword`" ) )
  1375.         return 0
  1376.     fi
  1377.     COMPREPLY=( $( compgen -W 'start stop reload abort flush check' -- \
  1378.         "`_get_cword`" ) )
  1379. }
  1380. complete -F _postfix postfix
  1381.  
  1382. # postalias(1) and postmap(1)
  1383. #
  1384. _postmap()
  1385. {
  1386.     local cur prev len idx
  1387.  
  1388.     cur=`_get_cword`
  1389.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1390.  
  1391.     if [[ $cur == '-' ]]; then
  1392.         COMPREPLY=(-N -f -i -n -o -p -r -v -w -c -d -q)
  1393.         return 0
  1394.     fi
  1395.     if [[ $prev == '-c' ]]; then
  1396.         _filedir -d
  1397.         return 0
  1398.     fi
  1399.     if [[ $prev == -[dq] ]]; then
  1400.         return 0
  1401.     fi
  1402.  
  1403.     if [[ "$cur" == *:* ]]; then
  1404.                COMPREPLY=( $( compgen -f -- ${cur#*:} ) )
  1405.     else
  1406.         len=${#cur}
  1407.         idx=0
  1408.         for pval in $( /usr/sbin/postconf -m ); do
  1409.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1410.                 COMPREPLY[$idx]="$pval:"
  1411.                 idx=$(($idx+1))
  1412.             fi
  1413.         done
  1414.         if [[ $idx -eq 0 ]]; then
  1415.             COMPREPLY=( $( compgen -f -- "$cur" ) )
  1416.         fi
  1417.     fi
  1418.     return 0
  1419. }
  1420. complete -F _postmap postmap postalias
  1421.  
  1422. # postcat(1)
  1423. #
  1424. _postcat()
  1425. {
  1426.     local cur prev pval len idx qfile
  1427.  
  1428.     cur=`_get_cword`
  1429.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1430.  
  1431.     if [[ $cur == '-' ]]; then
  1432.         COMPREPLY=(-c -q -v)
  1433.         return 0
  1434.     fi
  1435.     if [[ $prev == '-c' ]]; then
  1436.         _filedir -d
  1437.         return 0
  1438.     fi
  1439.  
  1440.     qfile=0
  1441.     for idx in "${COMP_WORDS[@]}"; do
  1442.         [[ "$idx" = -q ]] && qfile=1 && break
  1443.     done
  1444.     if [[ $qfile == 1 ]]; then
  1445.         len=${#cur}
  1446.         idx=0
  1447.         for pval in $( mailq | \
  1448.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
  1449.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1450.                 COMPREPLY[$idx]=$pval
  1451.                 idx=$(($idx+1))
  1452.             fi
  1453.         done
  1454.         return 0
  1455.     else
  1456.         _filedir
  1457.         return 0
  1458.     fi
  1459. }
  1460. complete -F _postcat postcat
  1461.  
  1462. # postconf(1)
  1463. #
  1464. _postconf()
  1465. {
  1466.     local cur prev pval len idx eqext
  1467.  
  1468.     cur=`_get_cword`
  1469.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1470.     if [[ $cur == '-' ]]; then
  1471.         COMPREPLY=(-c -d -e -h -m -l -n -v)
  1472.         return 0
  1473.     fi
  1474.     if [[ $prev == '-c' ]]; then
  1475.         _filedir -d
  1476.         return 0
  1477.     fi
  1478.     if [[ $prev == '-e' ]]; then
  1479.         cur=${cur#[\"\']}
  1480.         eqext='='
  1481.     fi
  1482.     len=${#cur}
  1483.     idx=0
  1484.     for pval in $( /usr/sbin/postconf | cut -d ' ' -f 1 ); do
  1485.         if [[ "$cur" == "${pval:0:$len}" ]]; then
  1486.             COMPREPLY[$idx]="$pval$eqext"
  1487.             idx=$(($idx+1))
  1488.         fi
  1489.     done
  1490.     return 0
  1491. }
  1492. complete -F _postconf postconf
  1493.  
  1494. # postsuper(1)
  1495. #
  1496. _postsuper()
  1497. {
  1498.     local cur prev pval len idx
  1499.  
  1500.     cur=`_get_cword`
  1501.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1502.  
  1503.     if [[ $cur == '-' ]]; then
  1504.         COMPREPLY=(-c -d -h -H -p -r -s -v)
  1505.         return 0
  1506.     fi
  1507.     case $prev in
  1508.     -[dr])
  1509.         len=${#cur}
  1510.         idx=0
  1511.         for pval in $( echo ALL; mailq | \
  1512.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
  1513.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1514.                 COMPREPLY[$idx]=$pval
  1515.                 idx=$(($idx+1))
  1516.             fi
  1517.         done
  1518.         return 0
  1519.         ;;
  1520.     -h)
  1521.         len=${#cur}
  1522.         idx=0
  1523.         for pval in $( echo ALL; mailq | \
  1524.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do
  1525.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1526.                 COMPREPLY[$idx]=$pval
  1527.                 idx=$(($idx+1))
  1528.             fi
  1529.         done
  1530.         return 0
  1531.         ;;
  1532.     -H)
  1533.         len=${#cur}
  1534.         idx=0
  1535.         for pval in $( echo ALL; mailq | \
  1536.             sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do
  1537.             if [[ "$cur" == "${pval:0:$len}" ]]; then
  1538.                 COMPREPLY[$idx]=$pval
  1539.                 idx=$(($idx+1))
  1540.             fi
  1541.         done
  1542.         return 0
  1543.         ;;
  1544.     esac
  1545.     COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) )
  1546.     return 0
  1547. }
  1548. complete -F _postsuper postsuper
  1549. }
  1550.  
  1551. # cvs(1) completion
  1552. #
  1553. have cvs && {
  1554. set_prefix()
  1555. {
  1556.     [ -z ${prefix:-} ] || prefix=${cur%/*}/
  1557.     [ -r ${prefix:-}CVS/Entries ] || prefix=""
  1558. }
  1559.  
  1560. get_entries()
  1561. {
  1562.     local IFS=$'\n'
  1563.     [ -r ${prefix:-}CVS/Entries ] && \
  1564.     entries=$(cut -d/ -f2 -s ${prefix:-}CVS/Entries)
  1565. }
  1566.  
  1567. get_modules()
  1568. {
  1569.     if [ -n "$prefix" ]; then
  1570.         COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
  1571.     else
  1572.         COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
  1573.     fi
  1574. }
  1575.  
  1576. _cvs()
  1577. {
  1578.     local cur count mode i cvsroot cvsroots pwd
  1579.     local -a flags miss files entries changed newremoved
  1580.  
  1581.     COMPREPLY=()
  1582.     cur=`_get_cword`
  1583.  
  1584.     count=0
  1585.     for i in "${COMP_WORDS[@]}"; do
  1586.         [ $count -eq $COMP_CWORD ] && break
  1587.         # Last parameter was the CVSROOT, now go back to mode selection
  1588.         if [ "${COMP_WORDS[((count))]}" == "$cvsroot" -a "$mode" == "cvsroot" ]; then
  1589.             mode=""
  1590.         fi
  1591.         if [ -z "$mode" ]; then
  1592.             case $i in
  1593.             -d)
  1594.                 mode=cvsroot
  1595.                 cvsroot=${COMP_WORDS[((count+1))]}
  1596.                 ;;
  1597.             @(ad?(d)|new))
  1598.                 mode=add
  1599.                 ;;
  1600.             @(adm?(in)|rcs))
  1601.                 mode=admin
  1602.                 ;;
  1603.             ann?(notate))
  1604.                 mode=annotate
  1605.                 ;;
  1606.             @(checkout|co|get))
  1607.                 mode=checkout
  1608.                 ;;
  1609.             @(com?(mit)|ci))
  1610.                 mode=commit
  1611.                 ;;
  1612.             di?(f?(f)))
  1613.                 mode=diff
  1614.                 ;;
  1615.             ex?(p?(ort)))
  1616.                 mode=export
  1617.                 ;;
  1618.             ?(un)edit)
  1619.                 mode=$i
  1620.                 ;;
  1621.             hi?(s?(tory)))
  1622.                 mode=history
  1623.                 ;;
  1624.             im?(p?(ort)))
  1625.                 mode=import
  1626.                 ;;
  1627.             re?(l?(ease)))
  1628.                 mode=release
  1629.                 ;;
  1630.             ?(r)log)
  1631.                 mode=log
  1632.                 ;;
  1633.             @(rdiff|patch))
  1634.                 mode=rdiff
  1635.                 ;;
  1636.             @(remove|rm|delete))
  1637.                 mode=remove
  1638.                 ;;
  1639.             @(rtag|rfreeze))
  1640.                 mode=rtag
  1641.                 ;;
  1642.             st?(at?(us)))
  1643.                 mode=status
  1644.                 ;;
  1645.             @(tag|freeze))
  1646.                 mode=tag
  1647.                 ;;
  1648.             up?(d?(ate)))
  1649.                 mode=update
  1650.                 ;;
  1651.             *)
  1652.                 ;;
  1653.             esac
  1654.         elif [[ "$i" = -* ]]; then
  1655.             flags=( "${flags[@]}" $i )
  1656.         fi
  1657.         count=$((++count))
  1658.     done
  1659.  
  1660.     case "$mode" in
  1661.     add)
  1662.         if [[ "$cur" != -* ]]; then
  1663.             set_prefix
  1664.             if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then
  1665.                 get_entries
  1666.                 [ -z "$cur" ] && \
  1667.                 files=$( command ls -Ad !(CVS) ) || \
  1668.                 files=$( command ls -d ${cur}* 2>/dev/null )
  1669.                 for i in "${entries[@]}"; do
  1670.                     files=( ${files[@]/#$i//} )
  1671.                 done
  1672.                 COMPREPLY=( $( compgen -W '${files[@]}' -- \
  1673.                            $cur ) )
  1674.             fi
  1675.         else
  1676.             COMPREPLY=( $( compgen -W '-k -m' -- $cur ) )
  1677.         fi
  1678.         ;;
  1679.     admin)
  1680.         if [[ "$cur" = -* ]]; then
  1681.             COMPREPLY=( $( compgen -W '-i -a -A -e -b -c -k -l -u \
  1682.                            -L -U -m -M -n -N -o -q -I \
  1683.                            -s -t -t- -T -V -x -z' -- \
  1684.                     $cur ) )
  1685.         fi
  1686.         ;;
  1687.     annotate)
  1688.         if [[ "$cur" = -* ]]; then
  1689.             COMPREPLY=( $( compgen -W '-D -F -f -l -R -r' -- $cur ) )
  1690.         else
  1691.             get_entries
  1692.             COMPREPLY=( $( compgen -W '${entries[@]}' -- $cur ) )
  1693.         fi
  1694.         ;;
  1695.     checkout)
  1696.         if [[ "$cur" != -* ]]; then
  1697.             [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  1698.             COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
  1699.                     awk '{print $1}' ) )
  1700.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) )
  1701.         else
  1702.             COMPREPLY=( $( compgen -W '-A -N -P -R -c -f -l -n -p \
  1703.                           -s -r -D -d -k -j' -- $cur ) )
  1704.         fi
  1705.         ;;
  1706.     commit)
  1707.         set_prefix
  1708.  
  1709.         if [[ "$cur" != -* ]] && [ -r ${prefix:-}CVS/Entries ]; then
  1710.             # if $COMP_CVS_REMOTE is not null, 'cvs commit' will
  1711.             # complete on remotely checked-out files (requires
  1712.             # passwordless access to the remote repository
  1713.             if [ -n "${COMP_CVS_REMOTE:-}" ]; then
  1714.                 # this is the least computationally intensive
  1715.                 # way found so far, but other changes
  1716.                 # (something other than changed/removed/new)
  1717.                 # may be missing
  1718.                 changed=( $( cvs -q diff --brief 2>&1 | \
  1719.                 sed -ne 's/^Files [^ ]* and \([^ ]*\) differ$/\1/p' ) )
  1720.                 newremoved=( $( cvs -q diff --brief 2>&1 | \
  1721.                 sed -ne 's/^cvs diff: \([^ ]*\) .*, no comparison available$/\1/p' ) )
  1722.                 COMPREPLY=( $( compgen -W '${changed[@]:-} \
  1723.                            ${newremoved[@]:-}' -- $cur ) )
  1724.             else
  1725.                 _filedir
  1726.             fi
  1727.         else
  1728.             COMPREPLY=( $( compgen -W '-n -R -l -f -F -m -r' -- \
  1729.                        $cur ) )
  1730.         fi
  1731.         ;;
  1732.     cvsroot)
  1733.         if [ -r ~/.cvspass ]; then
  1734.             # Ugly escaping because of bash treating ':' specially
  1735.             cvsroots=$( sed 's/^[^ ]* //; s/:/\\:/g' ~/.cvspass )
  1736.             COMPREPLY=( $( compgen -W '$cvsroots' -- $cur ) )
  1737.         fi
  1738.         ;;
  1739.     export)
  1740.         if [[ "$cur" != -* ]]; then
  1741.             [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  1742.             COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
  1743.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- $cur ) )
  1744.         else
  1745.             COMPREPLY=( $( compgen -W '-N -f -l -R -n \
  1746.                           -r -D -d -k' -- $cur ) )
  1747.         fi
  1748.         ;;
  1749.     diff)
  1750.         if [[ "$cur" == -* ]]; then
  1751.             _longopt diff
  1752.         else
  1753.             get_entries
  1754.             COMPREPLY=( $( compgen -W '${entries[@]:-}' -- $cur ) )
  1755.         fi
  1756.         ;;
  1757.     remove)
  1758.         if [[ "$cur" != -* ]]; then
  1759.             set_prefix
  1760.             if [ $COMP_CWORD -gt 1 -a -r ${prefix:-}CVS/Entries ]; then
  1761.                 get_entries
  1762.                 # find out what files are missing
  1763.                 for i in "${entries[@]}"; do
  1764.                     [ ! -r "$i" ] && miss=( "${miss[@]}" $i )
  1765.                 done
  1766.                 COMPREPLY=( $(compgen -W '${miss[@]:-}' -- $cur) )
  1767.             fi
  1768.         else
  1769.             COMPREPLY=( $( compgen -W '-f -l -R' -- $cur ) )
  1770.         fi
  1771.         ;;
  1772.     import)
  1773.         if [[ "$cur" != -* ]]; then
  1774.             # starts with same algorithm as checkout
  1775.             [ -z "$cvsroot" ] && cvsroot=$CVSROOT
  1776.             prefix=${cur%/*}
  1777.             if [ -r ${cvsroot}/${prefix} ]; then
  1778.                 get_modules
  1779.                 COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
  1780.                 COMPREPLY=( ${COMPREPLY[@]#\/} )
  1781.             fi
  1782.             pwd=$( pwd )
  1783.             pwd=${pwd##*/}
  1784.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $pwd' -- \
  1785.                        $cur ) )
  1786.         else
  1787.             COMPREPLY=( $( compgen -W '-d -k -I -b -m -W' -- $cur ))
  1788.         fi
  1789.         ;;
  1790.     update)
  1791.         if [[ "$cur" = -* ]]; then
  1792.             COMPREPLY=( $( compgen -W '-A -P -C -d -f -l -R -p \
  1793.                            -k -r -D -j -I -W' -- \
  1794.                            $cur ) )
  1795.         fi
  1796.         ;;
  1797.     "")
  1798.         COMPREPLY=( $( compgen -W 'add admin annotate checkout ci co \
  1799.                        commit diff delete edit export \
  1800.                        freeze get history import log new \
  1801.                        patch rcs rdiff release remove \
  1802.                        rfreeze rlog rm rtag stat status \
  1803.                        tag unedit up update -H -Q -q -b \
  1804.                        -d -e -f -l -n -t -r -v -w -x -z \
  1805.                        --help --version' -- $cur ) )
  1806.         ;;
  1807.     *)
  1808.         ;;
  1809.     esac
  1810.  
  1811.     return 0
  1812. }
  1813. complete -F _cvs $default cvs
  1814. }
  1815.  
  1816. have rpm && {
  1817. # helper functions for rpm completion
  1818. #
  1819. _rpm_installed_packages()
  1820. {
  1821.     local ver nodig nosig
  1822.  
  1823.     if [ -r /var/log/rpmpkgs -a \
  1824.         /var/log/rpmpkgs -nt /var/lib/rpm/Packages ]; then
  1825.         # using RHL 7.2 or later - this is quicker than querying the DB
  1826.         COMPREPLY=( $( sed -ne \
  1827.         's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+.*\.rpm$|\1|p' \
  1828.                 /var/log/rpmpkgs ) )
  1829.     else
  1830.         nodig=""
  1831.         nosig=""
  1832.         ver=$(rpm --version)
  1833.         ver=${ver##* }
  1834.  
  1835.         if [[ "$ver" > "4.0.4" ]]; then
  1836.             nodig="--nodigest"
  1837.         fi
  1838.         if [[ "$ver" > "4.0.99" ]]; then
  1839.             nosig="--nosignature"
  1840.         fi
  1841.  
  1842.         COMPREPLY=( $( rpm -qa $nodig $nosig | sed -ne \
  1843.         's|^\('$cur'.*\)-[0-9a-zA-Z._]\+-[0-9a-z.@]\+$|\1|p' ) )
  1844.     fi
  1845. }
  1846.  
  1847. _rpm_groups()
  1848. {
  1849.     local IFS=$'\t'
  1850.     # remove trailing backslash, or grep will complain
  1851.     cur=${cur%"\\"}
  1852.     COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat '%{group}\n' | \
  1853.                grep "^$cur" ) )
  1854.     # backslash escape spaces and translate newlines to tabs
  1855.     COMPREPLY=( $( echo "${COMPREPLY[@]}" | sed 's/ /\\ /g' | tr '\n' '\t' ) )
  1856. }
  1857.  
  1858. # rpm(8) completion
  1859. #
  1860. _rpm()
  1861. {
  1862.     local cur prev ver nodig nosig
  1863.  
  1864.     COMPREPLY=()
  1865.     cur=`_get_cword`
  1866.     prev=${COMP_WORDS[COMP_CWORD-1]}
  1867.     nodig=""
  1868.     nosig=""
  1869.     ver=$(rpm --version); ver=${ver##* }
  1870.  
  1871.     if [[ "$ver" > "4.0.4" ]]; then
  1872.         nodig="--nodigest"
  1873.     fi
  1874.     if [[ "$ver" > "4.0.99" ]]; then
  1875.         nosig="--nosignature"
  1876.     fi
  1877.  
  1878.     if [ $COMP_CWORD -eq 1 ]; then
  1879.         # first parameter on line
  1880.         case "$cur" in
  1881.         -b*)
  1882.             COMPREPLY=( $( compgen -W '-ba -bb -bc -bi -bl -bp -bs'\
  1883.                        -- $cur ) )
  1884.             ;;
  1885.         -t*)
  1886.             COMPREPLY=( $( compgen -W '-ta -tb -tc -ti -tl -tp -ts'\
  1887.                        -- $cur ) )
  1888.             ;;
  1889.         --*)
  1890.             COMPREPLY=( $( compgen -W '--help --version --initdb \
  1891.             --checksig --recompile --rebuild --resign --addsign \
  1892.             --rebuilddb --showrc --setperms --setugids --tarbuild \
  1893.             --eval --install --upgrade --query --freshen --erase \
  1894.             --verify --querytags --rmsource --rmspec --clean \
  1895.             --import' -- $cur ) )
  1896.             ;;
  1897.         *)
  1898.             COMPREPLY=( $( compgen -W '-b -e -F -i -q -t -U -V' \
  1899.                        -- $cur ) )
  1900.             ;;
  1901.         esac
  1902.  
  1903.     return 0
  1904.     fi
  1905.  
  1906.     case "$prev" in
  1907.     --@(@(db|exclude)path|prefix|relocate|root))
  1908.         _filedir -d
  1909.         return 0
  1910.         ;;
  1911.     --eval)
  1912.         # get a list of macros
  1913.         COMPREPLY=( $( sed -ne 's|^\(%'${cur#\%}'[^ '$'\t'']*\).*$|\1|p' \
  1914.                    /usr/lib/rpm/macros ) )
  1915.         return 0
  1916.         ;;
  1917.     --pipe)
  1918.         COMPREPLY=( $( compgen -c -- $cur ) )
  1919.         return 0
  1920.         ;;
  1921.     --rcfile)
  1922.         _filedir
  1923.         return 0
  1924.         ;;
  1925.     --specfile)
  1926.         # complete on .spec files
  1927.         _filedir spec
  1928.         return 0
  1929.         ;;
  1930.     --whatprovides)
  1931.         if [[ "$cur" == */* ]]; then
  1932.             _filedir
  1933.         else
  1934.         # complete on capabilities
  1935.             COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
  1936.                     '%{providename}\n' | grep "^$cur" ) )
  1937.         fi
  1938.         return 0
  1939.         ;;
  1940.     --whatrequires)
  1941.         # complete on capabilities
  1942.         COMPREPLY=( $( rpm -qa $nodig $nosig --queryformat \
  1943.                 '%{requirename}\n' | grep "^$cur" ) )
  1944.         return 0
  1945.         ;;
  1946.     esac
  1947.  
  1948.     case "${COMP_WORDS[1]}" in
  1949.     -@([iFU]*|-install|-freshen|-upgrade))
  1950.         if [[ "$cur" == -* ]]; then
  1951.             COMPREPLY=( $( compgen -W '--percent --force --test \
  1952.             --replacepkgs --replacefiles --root --excludedocs \
  1953.             --includedocs --noscripts --rcfile --ignorearch \
  1954.             --dbpath --prefix --ignoreos --nodeps --allfiles \
  1955.             --ftpproxy --ftpport --justdb --httpproxy --httpport \
  1956.             --noorder --relocate --badreloc --notriggers \
  1957.             --excludepath --ignoresize --oldpackage --define \
  1958.             --eval --pipe --queryformat --repackage --nosuggests \
  1959.             --nodigest --nosignature' -- $cur ) )
  1960.         else
  1961.             _filedir 'rpm'
  1962.         fi
  1963.         ;;
  1964.     -@(e|-erase))
  1965.         if [[ "$cur" == -* ]]; then
  1966.             COMPREPLY=( $( compgen -W '--allmatches --noscripts \
  1967.             --notriggers --nodeps --test --repackage' -- $cur ) )
  1968.         else
  1969.             _rpm_installed_packages
  1970.         fi
  1971.         ;;
  1972.     -@(q*|-query))
  1973.         # check whether we're doing file completion
  1974.         if [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  1975.             if [[ "$cur" == -* ]]; then
  1976.             COMPREPLY=( $( compgen -W '--scripts --root \
  1977.                 --rcfile --requires --ftpport --ftpproxy \
  1978.                 --httpproxy --httpport --provides --triggers \
  1979.                 --dump --changelog --dbpath \
  1980.                 --last --filesbypkg \
  1981.                 --info --list --state \
  1982.                 --docfiles --configfiles --queryformat \
  1983.                 --conflicts --obsoletes \
  1984.                 --nodigest --nosignature \
  1985.                 --triggerscripts' -- $cur ) )
  1986.             else
  1987.             _filedir
  1988.             fi
  1989.         elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  1990.             _rpm_groups
  1991.         elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  1992.             # uninstalled package completion
  1993.             if [[ "$cur" == -* ]]; then
  1994.                 COMPREPLY=( $( compgen -W '--scripts --root \
  1995.                 --rcfile --whatprovides --whatrequires \
  1996.                 --requires --triggeredby --ftpport --ftpproxy \
  1997.                 --httpproxy --httpport --provides --triggers \
  1998.                 --dump --changelog --dbpath --filesbypkg \
  1999.                 --define --eval --pipe --showrc --info --list \
  2000.                 --state --docfiles --configfiles --queryformat\
  2001.                 --conflicts --obsoletes --nodigest \
  2002.                 --nosignature' -- $cur ) )
  2003.             else
  2004.                 _filedir 'rpm'
  2005.             fi
  2006.         else
  2007.             # installed package completion
  2008.             if [[ "$cur" == -* ]]; then
  2009.                 COMPREPLY=( $( compgen -W '--scripts --root \
  2010.                 --rcfile --whatprovides --whatrequires \
  2011.                 --requires --triggeredby --ftpport --ftpproxy \
  2012.                 --httpproxy --httpport --provides --triggers \
  2013.                 --dump --changelog --dbpath --specfile \
  2014.                 --querybynumber --last --filesbypkg --define \
  2015.                 --eval --pipe --showrc --info --list --state \
  2016.                 --docfiles --configfiles --queryformat \
  2017.                 --conflicts --obsoletes --pkgid --hdrid \
  2018.                 --fileid --tid --nodigest --nosignature \
  2019.                 --triggerscripts' -- $cur ) )
  2020.             elif [ "${COMP_LINE#* -*([^ -])a}" == "$COMP_LINE" ]; then
  2021.                 _rpm_installed_packages
  2022.             fi
  2023.         fi
  2024.         ;;
  2025.     -@(K*|-checksig))
  2026.         if [[ "$cur" == -* ]]; then
  2027.             COMPREPLY=( $( compgen -W '--nopgp --nogpg --nomd5 \
  2028.                     --nodigest --nosignature' -- $cur ) )
  2029.         else
  2030.             _filedir 'rpm'
  2031.         fi
  2032.         ;;
  2033.     -@([Vy]*|-verify))
  2034.         if [[ "$cur" == -* ]]; then
  2035.             COMPREPLY=( $( compgen -W '--root --rcfile --dbpath \
  2036.             --nodeps --nogroup --nolinkto --nomode --nomtime \
  2037.             --nordev --nouser --nofiles --noscripts --nomd5 \
  2038.             --querytags --specfile --whatrequires --whatprovides \
  2039.             --nodigest --nosignature' -- $cur ) )
  2040.         # check whether we're doing file completion
  2041.         elif [ "${COMP_LINE#* -*([^ -])f}" != "$COMP_LINE" ]; then
  2042.             _filedir
  2043.         elif [ "${COMP_LINE#* -*([^ -])g}" != "$COMP_LINE" ]; then
  2044.             _rpm_groups
  2045.         elif [ "${COMP_LINE#* -*([^ -])p}" != "$COMP_LINE" ]; then
  2046.             _filedir 'rpm'
  2047.         else
  2048.             _rpm_installed_packages
  2049.         fi
  2050.         ;;
  2051.     -[bt]*)
  2052.         if [[ "$cur" == -* ]]; then
  2053.             COMPREPLY=( $( compgen -W '--short-circuit --timecheck \
  2054.             --clean --rmsource --rmspec --test --sign --buildroot \
  2055.             --target -- buildarch --buildos --nobuild --nodeps \
  2056.             --nodirtokens' -- $cur ) )
  2057.         elif [[ ${COMP_WORDS[1]} == -b* ]]; then
  2058.             _filedir 'spec'
  2059.         else
  2060.             _filedir '@(tgz|tar.@(gz|bz2))'
  2061.         fi
  2062.         ;;
  2063.     --re@(build|compile))
  2064.         if [[ "$cur" == -* ]]; then
  2065.             COMPREPLY=( $( compgen -W '--nodeps --rmsource \
  2066.               --rmspec --sign --nodirtokens --target' -- $cur ) )
  2067.         else
  2068.             _filedir '?(no)src.rpm'
  2069.         fi
  2070.         ;;
  2071.     --tarbuild)
  2072.         _filedir '@(tgz|tar.@(gz|bz2))'
  2073.         ;;
  2074.     --@(re|add)sign)
  2075.         _filedir 'rpm'
  2076.         ;;
  2077.     --set@(perms|gids))
  2078.         _rpm_installed_packages
  2079.         ;;
  2080.     --@(clean|rms@(ource|pec)))
  2081.         if [[ "$cur" == -* ]]; then
  2082.             COMPREPLY=( $( compgen -W '--clean --rmsource \
  2083.                     --rmspec' -- $cur ) )
  2084.         else
  2085.             _filedir 'spec'
  2086.         fi
  2087.         ;;
  2088.     --@(import|dbpath|root))
  2089.         if [[ "$cur" == -* ]]; then
  2090.             COMPREPLY=( $( compgen -W '--import --dbpath --root' \
  2091.                     -- $cur ) )
  2092.         else
  2093.             _filedir
  2094.         fi
  2095.         ;;
  2096.     esac
  2097.  
  2098.     return 0
  2099. }
  2100. complete -F _rpm $filenames rpm rpmbuild
  2101. }
  2102.  
  2103. # Debian apt-get(8) completion.
  2104. #
  2105. have apt-get &&
  2106. _apt_get()
  2107. {
  2108.     local cur prev special i
  2109.  
  2110.     COMPREPLY=()
  2111.     cur=`_get_cword`
  2112.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2113.  
  2114.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2115.         if [[ ${COMP_WORDS[i]} == @(install|remove|autoremove|purge|source|build-dep) ]]; then
  2116.             special=${COMP_WORDS[i]}
  2117.         fi
  2118.     done
  2119.  
  2120.     if [ -n "$special" ]; then
  2121.         case $special in
  2122.         remove|autoremove|purge)
  2123.             if [ -f /etc/debian_version ]; then
  2124.                 # Debian system
  2125.                 COMPREPLY=( $( _comp_dpkg_installed_packages \
  2126.                         $cur ) )
  2127.             else
  2128.                 # assume RPM based
  2129.                 _rpm_installed_packages
  2130.             fi
  2131.             return 0
  2132.             ;;
  2133.         *)
  2134.             COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2135.             return 0
  2136.             ;;
  2137.  
  2138.         esac
  2139.     fi
  2140.  
  2141.     case "$prev" in
  2142.         -@(c|-config-file))
  2143.               _filedir
  2144.              return 0
  2145.              ;;
  2146.  
  2147.         -@(t|-target-release|-default-release))
  2148.              COMPREPLY=( $( apt-cache policy | \
  2149.                     grep "release.o=Debian,a=$cur" | \
  2150.                     sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null) )
  2151.              return 0
  2152.              ;;
  2153.  
  2154.     esac
  2155.  
  2156.     if [[ "$cur" == -* ]]; then
  2157.  
  2158.         COMPREPLY=( $( compgen -W '-d -f -h -v -m -q -s -y \
  2159.                 -u -t -b -c -o --download-only --fix-broken \
  2160.                 --help --version --ignore-missing \
  2161.                 --fix-missing --no-download --quiet --simulate \
  2162.                 --just-print --dry-run --recon --no-act --yes \
  2163.                 --assume-yes --show-upgraded --only-source \
  2164.                 --compile --build --ignore-hold \
  2165.                 --target-release --no-upgrade --force-yes \
  2166.                 --print-uris --purge --reinstall \
  2167.                 --list-cleanup --default-release \
  2168.                 --trivial-only --no-remove --diff-only \
  2169.                 --no-install-recommends \
  2170.                 --tar-only --config-file --option --auto-remove' -- $cur ) )
  2171.     else
  2172.  
  2173.         COMPREPLY=( $( compgen -W 'update upgrade dselect-upgrade \
  2174.                 dist-upgrade install remove purge source build-dep \
  2175.                 check clean autoclean autoremove' -- $cur ) )
  2176.  
  2177.     fi
  2178.  
  2179.  
  2180.     return 0
  2181. } &&
  2182. complete -F _apt_get $filenames apt-get
  2183.  
  2184. # Debian apt-cache(8) completion.
  2185. #
  2186. have apt-cache &&
  2187. _apt_cache()
  2188. {
  2189.     local cur prev special i
  2190.  
  2191.     COMPREPLY=()
  2192.     cur=`_get_cword`
  2193.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2194.  
  2195.  
  2196.     if [ "$cur" != show ]; then
  2197.         for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2198.         if [[ ${COMP_WORDS[i]} == @(add|depends|dotty|madison|policy|rdepends|show?(pkg|src|)) ]]; then
  2199.             special=${COMP_WORDS[i]}
  2200.         fi
  2201.         done
  2202.     fi
  2203.  
  2204.  
  2205.     if [ -n "$special" ]; then
  2206.         case $special in
  2207.         add)
  2208.             _filedir
  2209.             return 0
  2210.             ;;
  2211.  
  2212.          *)
  2213.             COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2214.             return 0
  2215.             ;;
  2216.  
  2217.         esac
  2218.     fi
  2219.  
  2220.  
  2221.     case "$prev" in
  2222.          -@(c|p|s|-config-file|-@(pkg|src)-cache))
  2223.              _filedir
  2224.              return 0
  2225.              ;;
  2226.          search)
  2227.              if [[ "$cur" != -* ]]; then
  2228.                 return 0
  2229.              fi
  2230.              ;;
  2231.     esac
  2232.  
  2233.     if [[ "$cur" == -* ]]; then
  2234.  
  2235.         COMPREPLY=( $( compgen -W '-h -v -p -s -q -i -f -a -g -c \
  2236.                 -o --help --version --pkg-cache --src-cache \
  2237.                 --quiet --important --full --all-versions \
  2238.                 --no-all-versions --generate --no-generate \
  2239.                 --names-only --all-names --recurse \
  2240.                 --config-file --option --installed' -- $cur ) )
  2241.     else
  2242.  
  2243.         COMPREPLY=( $( compgen -W 'add gencaches show showpkg showsrc \
  2244.                 stats dump dumpavail unmet search search \
  2245.                 depends rdepends pkgnames dotty xvcg \
  2246.                 policy madison' -- $cur ) )
  2247.  
  2248.     fi
  2249.  
  2250.  
  2251.     return 0
  2252. } &&
  2253. complete -F _apt_cache $filenames apt-cache
  2254.  
  2255.  
  2256. # Debian aptitude(1) completion
  2257. #
  2258. have aptitude && {
  2259. have grep-status && {
  2260. _comp_dpkg_hold_packages()
  2261. {
  2262.     grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package
  2263. }
  2264. } || {
  2265. _comp_dpkg_hold_packages()
  2266. {
  2267.     grep -B 2 'hold' /var/lib/dpkg/status | grep "Package: $1" \
  2268.         | cut -d\  -f2
  2269. }
  2270. }
  2271.  
  2272. _aptitude()
  2273. {
  2274.     local cur dashoptions prev special i
  2275.  
  2276.     COMPREPLY=()
  2277.     cur=`_get_cword`
  2278.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2279.  
  2280.  
  2281.     dashoptions='-S -u -i -h --help --version -s --simulate -d \
  2282.              --download-only -P --prompt -y --assume-yes -F \
  2283.              --display-format -O --sort -w --width -f -r -g \
  2284.              --with-recommends --with-suggests -R -G \
  2285.              --without-recommends --without-suggests -t \
  2286.              --target-release -V --show-versions -D --show-deps\
  2287.              -Z -v --verbose --purge-unused'
  2288.  
  2289.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2290.         if [[ ${COMP_WORDS[i]} == @(install|reinstall|hold|unhold|markauto|unmarkauto|dist-upgrade|full-upgrade|download|show|forbid-version|purge|remove|changelog|why|why-not|keep|keep-all) ]]; then
  2291.         special=${COMP_WORDS[i]}
  2292.         fi
  2293.         #exclude some mutually exclusive options
  2294.         [[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i}
  2295.         [[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u}
  2296.     done
  2297.  
  2298.     if [[ -n "$special" ]]; then
  2299.        case $special in
  2300.            @(install|hold|markauto|unmarkauto|dist-upgrade|full-upgrade|download|show|changelog|why|why-not))
  2301.            COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2302.            return 0
  2303.            ;;
  2304.            @(purge|remove|reinstall|forbid-version))
  2305.              COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
  2306.            return 0
  2307.            ;;
  2308.            unhold)
  2309.              COMPREPLY=( $( _comp_dpkg_hold_packages $cur ) )
  2310.            return 0
  2311.            ;;
  2312.  
  2313.        esac
  2314.     fi
  2315.  
  2316.     case $prev in
  2317.         # don't complete anything if these options are found
  2318.         @(autoclean|clean|forget-new|search|upgrade|safe-upgrade|update|keep-all))
  2319.         return 0
  2320.         ;;
  2321.  
  2322.         -S)
  2323.         _filedir
  2324.         return 0
  2325.         ;;
  2326.  
  2327.         -@(t|-target-release|-default-release))
  2328.         COMPREPLY=( $( apt-cache policy | \
  2329.             grep "release.o=Debian,a=$cur" | \
  2330.             sed -e "s/.*a=\(\w*\).*/\1/" | uniq 2> /dev/null ) )
  2331.         return 0
  2332.         ;;
  2333.  
  2334.     esac
  2335.  
  2336.     if [[ "$cur" == -* ]]; then
  2337.         COMPREPLY=( $( compgen -W "$dashoptions" -- $cur ) )
  2338.     else
  2339.         COMPREPLY=( $( compgen -W 'update upgrade safe-upgrade forget-new clean \
  2340.                        autoclean install reinstall remove \
  2341.                        hold unhold purge markauto unmarkauto why why-not \
  2342.                        dist-upgrade full-upgrade download search show \
  2343.                        forbid-version changelog keep-all' -- $cur ) )
  2344.     fi
  2345.  
  2346.  
  2347.     return 0
  2348. }
  2349. complete -F _aptitude $default aptitude
  2350. }
  2351.  
  2352. # Debian apt-build(1) completion.
  2353. #
  2354. have apt-build &&
  2355. _apt_build()
  2356. {
  2357.     local cur prev special i
  2358.  
  2359.     COMPREPLY=()
  2360.     cur=`_get_cword`
  2361.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2362.  
  2363.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  2364.         if [[ ${COMP_WORDS[i]} == @(install|remove|source|info|clean) ]]; then
  2365.             special=${COMP_WORDS[i]}
  2366.         fi
  2367.     done
  2368.  
  2369.     if [ -n "$special" ]; then
  2370.         case $special in
  2371.         @(install|source|info))
  2372.             COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
  2373.             return 0
  2374.             ;;
  2375.         remove)
  2376.             COMPREPLY=( $( _comp_dpkg_installed_packages \
  2377.                     $cur ) )
  2378.             return 0
  2379.             ;;
  2380.         *)
  2381.             return 0
  2382.             ;;
  2383.         esac
  2384.     fi
  2385.  
  2386.     case "$prev" in
  2387.  
  2388.          --@(patch|build-dir|repository-dir))
  2389.            _filedir
  2390.            return 0
  2391.            ;;
  2392.  
  2393.          -@(h|-help))
  2394.            return 0
  2395.            ;;
  2396.  
  2397.     esac
  2398.  
  2399.     if [[ "$cur" == -* ]]; then
  2400.         COMPREPLY=( $( compgen -W '--help --show-upgraded -u --build-dir \
  2401.                   --repository-dir --build-only \
  2402.                   --build-command --reinstall --rebuild \
  2403.                   --remove-builddep --no-wrapper --purge \
  2404.                   --patch --patch-strip -p --yes -y \
  2405.                   --version -v --no-source' -- $cur ) )
  2406.  
  2407.     else
  2408.         COMPREPLY=( $( compgen -W 'update upgrade install remove \
  2409.                   source dist-upgrade world clean info \
  2410.                   clean-build update-repository ' -- $cur ) )
  2411.     fi
  2412.  
  2413.  
  2414.     return 0
  2415. } &&
  2416. complete -F _apt_build $filenames apt-build
  2417.  
  2418. # chsh(1) completion
  2419. #
  2420. _chsh()
  2421. {
  2422.     local cur prev
  2423.  
  2424.     COMPREPLY=()
  2425.     cur=`_get_cword`
  2426.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2427.  
  2428.     if [ "$prev" = "-s" ]; then
  2429.       if [ -f /etc/debian_version ]; then
  2430.         COMPREPLY=( $( </etc/shells ) )
  2431.       else
  2432.         COMPREPLY=( $( chsh -l | grep "^$cur" ) )
  2433.       fi
  2434.     else
  2435.       COMPREPLY=( $( compgen -u -- $cur ) )
  2436.     fi
  2437.  
  2438.     return 0
  2439. }
  2440. complete -F _chsh chsh
  2441.  
  2442. # chkconfig(8) completion
  2443. #
  2444. have chkconfig &&
  2445. _chkconfig()
  2446. {
  2447.     local cur prev
  2448.  
  2449.     COMPREPLY=()
  2450.     cur=`_get_cword`
  2451.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2452.  
  2453.     case "$prev" in
  2454.     @([1-6]|--@(list|add|del)))
  2455.         _services
  2456.         return 0
  2457.         ;;
  2458.     --level)
  2459.         COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- $cur ) )
  2460.         return 0
  2461.         ;;
  2462.     esac
  2463.  
  2464.     if [[ "$cur" == -* ]]; then
  2465.         COMPREPLY=( $( compgen -W '--list --add --del --level' -- $cur ) )
  2466.     else
  2467.         if [ $COMP_CWORD -eq 2 -o $COMP_CWORD -eq 4 ]; then
  2468.             COMPREPLY=( $( compgen -W 'on off reset' -- $cur ) )
  2469.         else
  2470.             _services
  2471.         fi
  2472.     fi
  2473. } &&
  2474. complete -F _chkconfig chkconfig
  2475.  
  2476. # This function provides simple user@host completion
  2477. #
  2478. _user_at_host() {
  2479.     local cur
  2480.  
  2481.     COMPREPLY=()
  2482.     cur=`_get_cword`
  2483.  
  2484.     if [[ $cur == *@* ]]; then
  2485.         _known_hosts
  2486.     else
  2487.         COMPREPLY=( $( compgen -u -- "$cur" ) )
  2488.     fi
  2489.  
  2490.     return 0
  2491. }
  2492. shopt -u hostcomplete && complete -F _user_at_host $nospace talk ytalk finger
  2493.  
  2494. # This function performs host completion based on ssh's known_hosts files,
  2495. # defaulting to standard host completion if they don't exist.
  2496. #
  2497. _known_hosts()
  2498. {
  2499.        local cur curd ocur user suffix aliases global_kh user_kh hosts i host
  2500.        local -a kh khd config
  2501.  
  2502.     COMPREPLY=()
  2503.     cur=`_get_cword`
  2504.     ocur=$cur
  2505.  
  2506.     [ "$1" = -a ] || [ "$2" = -a ] && aliases='yes'
  2507.     [ "$1" = -c ] || [ "$2" = -c ] && suffix=':'
  2508.     [[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
  2509.     kh=()
  2510.  
  2511.     # ssh config files
  2512.     [ -r /etc/ssh/ssh_config ] &&
  2513.       config=( "${config[@]}" "/etc/ssh/ssh_config" )
  2514.     [ -r "${HOME}/.ssh/config" ] &&
  2515.       config=( "${config[@]}" "${HOME}/.ssh/config" )
  2516.     [ -r "${HOME}/.ssh2/config" ] &&
  2517.       config=( "${config[@]}" "${HOME}/.ssh2/config" )
  2518.  
  2519.     if [ ${#config[@]} -gt 0 ]; then
  2520.         # expand path (if present) to global known hosts file
  2521.         global_kh=$( eval echo $( sed -ne 's/^[ \t]*[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) )
  2522.         # expand path (if present) to user known hosts file
  2523.         user_kh=$( eval echo $( sed -ne 's/^[ \t]*[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/\1/p' "${config[@]}" ) )
  2524.     fi
  2525.  
  2526.     # Global known_hosts files
  2527.     [ -r "$global_kh" ] &&
  2528.         kh=( "${kh[@]}" "$global_kh" )
  2529.     [ -r /etc/ssh/ssh_known_hosts ] &&
  2530.         kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts )
  2531.     [ -r /etc/ssh/ssh_known_hosts2 ] &&
  2532.         kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts2 )
  2533.     [ -r /etc/known_hosts ] &&
  2534.         kh=( "${kh[@]}" /etc/known_hosts )
  2535.     [ -r /etc/known_hosts2 ] &&
  2536.         kh=( "${kh[@]}" /etc/known_hosts2 )
  2537.     [ -d /etc/ssh2/knownhosts ] &&
  2538.         khd=( "${khd[@]}" /etc/ssh2/knownhosts/*pub )
  2539.  
  2540.     # User known_hosts files
  2541.     [ -r "$user_kh" ] &&
  2542.         kh=( "${kh[@]}" "$user_kh" )
  2543.     [ -r ~/.ssh/known_hosts ] &&
  2544.         kh=( "${kh[@]}" ~/.ssh/known_hosts )
  2545.     [ -r ~/.ssh/known_hosts2 ] &&
  2546.         kh=( "${kh[@]}" ~/.ssh/known_hosts2 )
  2547.     [ -d ~/.ssh2/hostkeys ] &&
  2548.         khd=( "${khd[@]}" ~/.ssh2/hostkeys/*pub )
  2549.  
  2550.     # If we have known_hosts files to use
  2551.     if [ ${#kh[@]} -gt 0 -o ${#khd[@]} -gt 0 ]; then
  2552.         # Escape slashes and dots in paths for awk
  2553.         cur=${cur//\//\\\/}
  2554.         cur=${cur//\./\\\.}
  2555.         curd=$cur
  2556.  
  2557.         if [[ "$cur" == [0-9]*.* ]]; then
  2558.         # Digits followed by a dot - just search for that
  2559.         cur="^$cur.*"
  2560.         elif [[ "$cur" == [0-9]* ]]; then
  2561.         # Digits followed by no dot - search for digits followed
  2562.         # by a dot
  2563.         cur="^$cur.*\."
  2564.         elif [ -z "$cur" ]; then
  2565.         # A blank - search for a dot or an alpha character
  2566.         cur="[a-z.]"
  2567.         else
  2568.         cur="^$cur"
  2569.         fi
  2570.  
  2571.         if [ ${#kh[@]} -gt 0 ]; then
  2572.  
  2573.         # FS needs to look for a comma separated list
  2574.         COMPREPLY=( $( awk 'BEGIN {FS=","}
  2575.                 /^[^|]/ {for (i=1; i<=2; ++i) { \
  2576.                        gsub(" .*$", "", $i); \
  2577.                        if ($i ~ /'$cur'/) {print $i} \
  2578.                 }}' "${kh[@]}" 2>/dev/null ) )
  2579.         fi
  2580.         if [ ${#khd[@]} -gt 0 ]; then
  2581.         # Needs to look for files called
  2582.         # .../.ssh2/key_22_<hostname>.pub
  2583.         # dont fork any processes, because in a cluster environment,
  2584.         # there can be hundreds of hostkeys
  2585.         for i in "${khd[@]}" ; do
  2586.             if [[ "$i" == *key_22_$curd*.pub ]] && [ -r "$i" ] ; then
  2587.             host=${i/#*key_22_/}
  2588.             host=${host/%.pub/}
  2589.             COMPREPLY=( "${COMPREPLY[@]}" $host )
  2590.             fi
  2591.         done
  2592.         fi
  2593.         # append any available aliases from config files
  2594.         if [ ${#config[@]} -gt 0 ] && [ -n "$aliases" ]; then
  2595.         local host_aliases=$( sed -ne 's/^[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\?['"$'\t '"']\+\([^*?]*\)$/\2/p' "${config[@]}" )
  2596.         hosts=$( compgen -W "$host_aliases" -- $ocur )
  2597.         COMPREPLY=( "${COMPREPLY[@]}" $hosts )
  2598.         fi
  2599.  
  2600.         # Now add results of normal hostname completion
  2601.         COMPREPLY=( "${COMPREPLY[@]}" $( compgen -A hostname -- $ocur ) )
  2602.  
  2603.         # apply suffix
  2604.         for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  2605.         COMPREPLY[i]=$user${COMPREPLY[i]}$suffix
  2606.         done
  2607.     else
  2608.         # Just do normal hostname completion
  2609.         COMPREPLY=( $( compgen -A hostname -S "$suffix" -- $cur ) )
  2610.     fi
  2611.  
  2612.     return 0
  2613. }
  2614. complete -F _known_hosts traceroute traceroute6 tracepath tracepath6 \
  2615.     ping ping6 fping fping6 telnet host nslookup rsh rlogin ftp dig ssh-installkeys mtr
  2616.  
  2617. # ssh(1) completion
  2618. #
  2619. have ssh && {
  2620. _ssh()
  2621. {
  2622.     local cur prev
  2623.     local -a config
  2624.  
  2625.     COMPREPLY=()
  2626.     cur=`_get_cword`
  2627.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2628.  
  2629.     case "$prev" in
  2630.     -*c)
  2631.         COMPREPLY=( $( compgen -W 'blowfish 3des 3des-cbc blowfish-cbc \
  2632.                arcfour cast128-cbc' -- $cur ) )
  2633.         ;;
  2634.     -*i)
  2635.         _filedir
  2636.         ;;
  2637.     -*l)
  2638.         COMPREPLY=( $( compgen -u -- $cur ) )
  2639.         ;;
  2640.     *)
  2641.         _known_hosts -a
  2642.  
  2643.         [ $COMP_CWORD -eq 1 ] || \
  2644.         COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- $cur ) )
  2645.     esac
  2646.  
  2647.     return 0
  2648. }
  2649. shopt -u hostcomplete && complete -F _ssh ssh slogin sftp xhost autossh
  2650.  
  2651. # scp(1) completion
  2652. #
  2653. _scp()
  2654. {
  2655.     local cur userhost path
  2656.  
  2657.     COMPREPLY=()
  2658.     cur=`_get_cword ":"`
  2659.  
  2660.     _expand || return 0
  2661.  
  2662.     if [[ "$cur" == *:* ]]; then
  2663.         local IFS=$'\t\n'
  2664.         # remove backslash escape from :
  2665.         cur=${cur/\\:/:}
  2666.         userhost=${cur%%?(\\):*}
  2667.         path=${cur#*:}
  2668.         # unescape spaces
  2669.         path=${path//\\\\\\\\ / }
  2670.         if [ -z "$path" ]; then
  2671.             # default to home dir of specified user on remote host
  2672.             path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
  2673.         fi
  2674.         # escape spaces; remove executables, aliases, pipes and sockets;
  2675.         # add space at end of file names
  2676.         COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
  2677.                    command ls -aF1d "$path*" 2>/dev/null | \
  2678.                    sed -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\\\\\\\\\&/g" \
  2679.                    -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
  2680.         return 0
  2681.     fi
  2682.  
  2683.     [[ "$cur" == */* ]] || _known_hosts -c -a
  2684.         local IFS=$'\t\n'
  2685.         COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
  2686.                 2>/dev/null | sed \
  2687.                 -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \
  2688.                 -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
  2689.     return 0
  2690. }
  2691. complete -F _scp $nospace scp
  2692. }
  2693.  
  2694. # rsync(1) completion
  2695. #
  2696. have rsync &&
  2697. _rsync()
  2698. {
  2699.     local cur prev shell i userhost path
  2700.  
  2701.     COMPREPLY=()
  2702.     cur=`_get_cword`
  2703.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2704.  
  2705.     _expand || return 0
  2706.  
  2707.     case "$prev" in
  2708.     --@(config|password-file|include-from|exclude-from))
  2709.         _filedir
  2710.         return 0
  2711.         ;;
  2712.     -@(T|-temp-dir|-compare-dest))
  2713.         _filedir -d
  2714.         return 0
  2715.         ;;
  2716.     -@(e|-rsh))
  2717.         COMPREPLY=( $( compgen -W 'rsh ssh' -- $cur ) )
  2718.         return 0
  2719.         ;;
  2720.     esac
  2721.  
  2722.     case "$cur" in
  2723.     -*)
  2724.         COMPREPLY=( $( compgen -W '-v -q  -c -a -r -R -b -u -l -L -H \
  2725.                 -p -o -g -D -t -S -n -W -x -B -e -C -I -T -P \
  2726.                 -z -h -4 -6 --verbose --quiet --checksum \
  2727.                 --archive --recursive --relative --backup \
  2728.                 --backup-dir --suffix= --update --links \
  2729.                 --copy-links --copy-unsafe-links --safe-links \
  2730.                 --hard-links --perms --owner --group --devices\
  2731.                 --times --sparse --dry-run --whole-file \
  2732.                 --no-whole-file --one-file-system \
  2733.                 --block-size= --rsh= --rsync-path= \
  2734.                 --cvs-exclude --existing --ignore-existing \
  2735.                 --delete --delete-excluded --delete-after \
  2736.                 --ignore-errors --max-delete= --partial \
  2737.                 --force --numeric-ids --timeout= \
  2738.                 --ignore-times --size-only --modify-window= \
  2739.                 --temp-dir= --compare-dest= --compress \
  2740.                 --exclude= --exclude-from= --include= \
  2741.                 --include-from= --version --daemon --no-detach\
  2742.                 --address= --config= --port= --blocking-io \
  2743.                 --no-blocking-io --stats --progress \
  2744.                 --log-format= --password-file= --bwlimit= \
  2745.                 --write-batch= --read-batch= --help' -- $cur ))
  2746.         ;;
  2747.     *:*)
  2748.         # find which remote shell is used
  2749.         shell=rsh
  2750.         for (( i=1; i < COMP_CWORD; i++ )); do
  2751.             if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then
  2752.                 shell=${COMP_WORDS[i+1]}
  2753.                 break
  2754.             fi
  2755.         done
  2756.         if [[ "$shell" == ssh ]]; then
  2757.             # remove backslash escape from :
  2758.             cur=${cur/\\:/:}
  2759.             userhost=${cur%%?(\\):*}
  2760.             path=${cur#*:}
  2761.             # unescape spaces
  2762.             path=${path//\\\\\\\\ / }
  2763.             if [ -z "$path" ]; then
  2764.                 # default to home dir of specified
  2765.                 # user on remote host
  2766.                 path=$(ssh -o 'Batchmode yes' \
  2767.                     $userhost pwd 2>/dev/null)
  2768.             fi
  2769.             # escape spaces; remove executables, aliases, pipes
  2770.             # and sockets; add space at end of file names
  2771.             COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
  2772.                 command ls -aF1d "$path*" 2>/dev/null | \
  2773.                 sed -e 's/ /\\\\\\\ /g' -e 's/[*@|=]$//g' \
  2774.                 -e 's/[^\/]$/& /g' ) )
  2775.         fi
  2776.         ;;
  2777.     *)
  2778.         _known_hosts -c -a
  2779.         _filedir
  2780.         ;;
  2781.     esac
  2782.  
  2783.     return 0
  2784. } &&
  2785. complete -F _rsync $nospace $filenames rsync
  2786.  
  2787. # Linux route(8) completion
  2788. #
  2789. [ $UNAME = Linux ] &&
  2790. _route()
  2791. {
  2792.     local cur prev
  2793.  
  2794.     COMPREPLY=()
  2795.     cur=`_get_cword`
  2796.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2797.  
  2798.     if [ "$prev" = dev ]; then
  2799.         COMPREPLY=( $( ifconfig -a | sed -ne 's|^\('$cur'[^ ]*\).*$|\1|p' ))
  2800.         return 0
  2801.     fi
  2802.  
  2803.     COMPREPLY=( $( compgen -W 'add del -host -net netmask metric mss \
  2804.                    window irtt reject mod dyn reinstate dev \
  2805.                    default gw' -- $cur ) )
  2806.  
  2807.     COMPREPLY=( $( echo " ${COMP_WORDS[@]}" | \
  2808.                (while read -d ' ' i; do
  2809.                [ "$i" == "" ] && continue
  2810.                # flatten array with spaces on either side,
  2811.                # otherwise we cannot grep on word
  2812.                # boundaries of first and last word
  2813.                COMPREPLY=" ${COMPREPLY[@]} "
  2814.                # remove word from list of completions
  2815.                COMPREPLY=( ${COMPREPLY/ $i / } )
  2816.             done
  2817.                echo "${COMPREPLY[@]}")
  2818.           ) )
  2819.     return 0
  2820. }
  2821. [ $UNAME = Linux ] && complete -F _route route
  2822.  
  2823. # GNU make(1) completion
  2824. #
  2825. have make || have gmake || have gnumake || have pmake &&
  2826. _make()
  2827. {
  2828.     local file makef makef_dir="." makef_inc cur prev i
  2829.  
  2830.     COMPREPLY=()
  2831.     cur=`_get_cword`
  2832.     prev=${COMP_WORDS[COMP_CWORD-1]}
  2833.  
  2834.     # --name value style option
  2835.     case $prev in
  2836.         -@(f|o|W))
  2837.             _filedir
  2838.             return 0
  2839.             ;;
  2840.         -@(I|C))
  2841.             _filedir -d
  2842.             return 0
  2843.             ;;
  2844.     esac
  2845.  
  2846.     # --name=value style option
  2847.     if [[ "$cur" == *=* ]]; then
  2848.         prev=${cur/=*/}
  2849.         cur=${cur/*=/}
  2850.         case "$prev" in
  2851.             --@(file|makefile))
  2852.                 _filedir
  2853.                 return 0
  2854.                 ;;
  2855.             --@(directory|include-dir))
  2856.                 _filedir -d
  2857.                 return 0
  2858.                 ;;
  2859.         esac
  2860.     fi
  2861.  
  2862.     if [[ "$cur" == -* ]]; then
  2863.         COMPREPLY=( $( compgen -W '-b -m -B -C -d -e -f -h -i -I\
  2864.             -j -l -k -n -o -p -q -r -R - s -S -t -v -w -W \
  2865.             --always-make --directory= --debug \
  2866.             --environment-overrides --file= --makefile= --help \
  2867.             --ignore-errors --include-dir= --jobs --load-average \
  2868.             --max-load --keep-going --just-print --dry-run \
  2869.             --recon --old-file= --assume-old= --print-data-base \
  2870.             --question --no-builtin-rules --no-builtin-variables \
  2871.             --silent --quiet --no-keep-goind --stop --touch \
  2872.             --version --print-directory --no-print-directory \
  2873.             --what-if= --new-file= --assume-new= \
  2874.             --warn-undefined-variables' -- $cur ) )
  2875.     else
  2876.         # before we check for makefiles, see if a path was specified
  2877.         # with -C
  2878.         for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
  2879.             if [[ ${COMP_WORDS[i]} == -C ]]; then
  2880.                 # eval for tilde expansion
  2881.                 eval makef_dir=${COMP_WORDS[i+1]}
  2882.                 break
  2883.             fi
  2884.         done
  2885.  
  2886.         # make reads `GNUmakefile', then `makefile', then `Makefile'
  2887.         if [ -f ${makef_dir}/GNUmakefile ]; then
  2888.             makef=${makef_dir}/GNUmakefile
  2889.         elif [ -f ${makef_dir}/makefile ]; then
  2890.             makef=${makef_dir}/makefile
  2891.         elif [ -f ${makef_dir}/Makefile ]; then
  2892.             makef=${makef_dir}/Makefile
  2893.         else
  2894.             makef=${makef_dir}/*.mk           # local convention
  2895.         fi
  2896.  
  2897.         # before we scan for targets, see if a Makefile name was
  2898.         # specified with -f
  2899.         for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
  2900.             if [[ ${COMP_WORDS[i]} == -f ]]; then
  2901.                 # eval for tilde expansion
  2902.                 eval makef=${COMP_WORDS[i+1]}
  2903.                 break
  2904.             fi
  2905.         done
  2906.  
  2907.         [ ! -f $makef ] && return 0
  2908.  
  2909.         # deal with included Makefiles
  2910.          makef_inc=$( grep -E '^-?include' $makef | sed -e "s,^.* ,"$makef_dir"/," )
  2911.  
  2912.          for file in $makef_inc; do
  2913.              [ -f $file ] && makef="$makef $file"
  2914.          done
  2915.  
  2916.         COMPREPLY=( $( awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \
  2917.                 {split($1,A,/ /);for(i in A)print A[i]}' \
  2918.                 $makef 2>/dev/null | command grep "^$cur" ))
  2919.     fi
  2920. } &&
  2921. complete -f -F _make $filenames make gmake gnumake pmake
  2922.  
  2923. # GNU tar(1) completion
  2924. #
  2925. _tar()
  2926. {
  2927.     local cur ext regex tar untar
  2928.  
  2929.     COMPREPLY=()
  2930.     cur=`_get_cword`
  2931.  
  2932.     if [ $COMP_CWORD -eq 1 ]; then
  2933.         COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) )
  2934.         return 0
  2935.     fi
  2936.  
  2937.     case "${COMP_WORDS[1]}" in
  2938.     ?(-)[cr]*f)
  2939.         _filedir
  2940.         return 0
  2941.         ;;
  2942.     +([^IZzjy])f)
  2943.         ext='t@(ar?(.@(Z|gz|bz?(2)))|gz|bz?(2))'
  2944.         regex='t\(ar\(\.\(Z\|gz\|bz2\?\)\)\?\|gz\|bz2\?\)'
  2945.         ;;
  2946.     *[Zz]*f)
  2947.         ext='t?(ar.)@(gz|Z)'
  2948.         regex='t\(ar\.\)\?\(gz\|Z\)'
  2949.         ;;
  2950.     *[Ijy]*f)
  2951.         ext='t?(ar.)bz?(2)'
  2952.         regex='t\(ar\.\)\?bz2\?'
  2953.         ;;
  2954.     *)
  2955.         _filedir
  2956.         return 0
  2957.         ;;
  2958.  
  2959.     esac
  2960.  
  2961.     if [[ "$COMP_LINE" == *$ext' ' ]]; then
  2962.         # complete on files in tar file
  2963.         #
  2964.         # get name of tar file from command line
  2965.         tar=$( echo "$COMP_LINE" | \
  2966.             sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' )
  2967.         # devise how to untar and list it
  2968.         untar=t${COMP_WORDS[1]//[^Izjyf]/}
  2969.  
  2970.         COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \
  2971.                 2>/dev/null ) )" -- "$cur" ) )
  2972.         return 0
  2973.     fi
  2974.  
  2975.     # file completion on relevant files
  2976.     _filedir "$ext"
  2977.  
  2978.     return 0
  2979. }
  2980. [ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar ||
  2981.     complete -F _tar $filenames tar
  2982.  
  2983. # jar(1) completion
  2984. #
  2985. have jar &&
  2986. _jar()
  2987. {
  2988.     local cur
  2989.  
  2990.     COMPREPLY=()
  2991.     cur=`_get_cword`
  2992.  
  2993.     if [ $COMP_CWORD = 1 ]; then
  2994.         COMPREPLY=( $( compgen -W 'c t x u' -- $cur ) )
  2995.         return 0
  2996.     fi
  2997.  
  2998.     case "${COMP_WORDS[1]}" in
  2999.         *c*f)
  3000.             _filedir
  3001.             ;;
  3002.         *f)
  3003.             _filedir '?(e|j|w)ar'
  3004.             ;;
  3005.         *)
  3006.             _filedir
  3007.             ;;
  3008.     esac
  3009. } &&
  3010. complete -F _jar $filenames jar
  3011.  
  3012. # Linux iptables(8) completion
  3013. #
  3014. have iptables &&
  3015. _iptables()
  3016. {
  3017.     local cur prev table chain
  3018.  
  3019.     COMPREPLY=()
  3020.     cur=`_get_cword`
  3021.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3022.     chain='s/^Chain \([^ ]\+\).*$/\1/p'
  3023.  
  3024.     if [[ $COMP_LINE == *-t\ *filter* ]]; then
  3025.         table="-t filter"
  3026.     elif [[ $COMP_LINE == *-t\ *nat* ]]; then
  3027.         table="-t nat"
  3028.     elif [[ $COMP_LINE == *-t\ *mangle* ]]; then
  3029.         table="-t mangle"
  3030.     fi
  3031.  
  3032.     case "$prev" in
  3033.     -*[AIDRPFXLZ])
  3034.         COMPREPLY=( $( compgen -W '`iptables $table -nL | \
  3035.                 sed -ne "s/^Chain \([^ ]\+\).*$/\1/p"`' -- $cur ) )
  3036.         ;;
  3037.     -*t)
  3038.         COMPREPLY=( $( compgen -W 'nat filter mangle' -- $cur ) )
  3039.         ;;
  3040.     -j)
  3041.         if [ "$table" = "-t filter" -o "$table" = "" ]; then
  3042.             COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
  3043.             `iptables $table -nL | sed -ne "$chain" \
  3044.             -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
  3045.             $cur ) )
  3046.         elif [ "$table" = "-t nat" ]; then
  3047.             COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
  3048.             MIRROR SNAT DNAT MASQUERADE `iptables $table -nL | \
  3049.             sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \
  3050.             -- $cur ) )
  3051.         elif [ "$table" = "-t mangle" ]; then
  3052.             COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
  3053.             MARK TOS `iptables $table -nL | sed -ne "$chain" \
  3054.             -e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
  3055.             $cur ) )
  3056.         fi
  3057.         ;;
  3058.     *)
  3059.         if [[ "$cur" == -* ]]; then
  3060.             COMPREPLY=( $( compgen -W '-i -o -s -d -p -f -m --append \
  3061.             --delete --insert --replace --list --flush --zero --new \
  3062.             --delete-chain --policy --rename-chain --proto --source \
  3063.             --destination --in-interface --jump --match --numeric \
  3064.             --out-interface --table --verbose --line-numbers --exact \
  3065.             --fragment --modprobe= --set-counters --version' -- "$cur") )
  3066.         fi
  3067.         ;;
  3068.     esac
  3069.  
  3070. } &&
  3071. complete -F _iptables iptables
  3072.  
  3073. # tcpdump(8) completion
  3074. #
  3075. have tcpdump &&
  3076. _tcpdump()
  3077. {
  3078.     local cur
  3079.  
  3080.     COMPREPLY=()
  3081.     cur=`_get_cword`
  3082.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3083.  
  3084.     case "$prev" in
  3085.         -@(r|w|F))
  3086.             _filedir
  3087.             return 0
  3088.             ;;
  3089.         -i)
  3090.             _available_interfaces -a
  3091.             return 0
  3092.             ;;
  3093.     esac
  3094.  
  3095.  
  3096.     if [[ "$cur" == -* ]]; then
  3097.         COMPREPLY=( $( compgen -W '-a -d -e -f -l -n -N -O -p \
  3098.             -q -R -S -t -u -v -x -C -F -i -m -r -s -T -w \
  3099.             -E' -- $cur ) )
  3100.     fi
  3101.  
  3102. } &&
  3103. complete -F _tcpdump tcpdump
  3104.  
  3105. # autorpm(8) completion
  3106. #
  3107. have autorpm &&
  3108. _autorpm()
  3109. {
  3110.     local cur
  3111.  
  3112.     COMPREPLY=()
  3113.     cur=`_get_cword`
  3114.  
  3115.     COMPREPLY=( $( compgen -W '--notty --debug --help --version \
  3116.                    auto add fullinfo info help install list \
  3117.                    remove set' -- $cur ) )
  3118.  
  3119. } &&
  3120. complete -F _autorpm autorpm
  3121.  
  3122. # This meta-cd function observes the CDPATH variable, so that cd additionally
  3123. # completes on directories under those specified in CDPATH.
  3124. #
  3125. _cd()
  3126. {
  3127.     local IFS=$'\t\n' cur=`_get_cword` i j k
  3128.  
  3129.     # try to allow variable completion
  3130.     if [[ "$cur" == ?(\\)\$* ]]; then
  3131.         COMPREPLY=( $( compgen -v -P '$' -- "${cur#?(\\)$}" ) )
  3132.         return 0
  3133.     fi
  3134.  
  3135.     # Use standard dir completion if no CDPATH or parameter starts with /,
  3136.     # ./ or ../
  3137.     if [ -z "${CDPATH:-}" ] || [[ "$cur" == ?(.)?(.)/* ]]; then
  3138.         _filedir -d
  3139.         return 0
  3140.     fi
  3141.  
  3142.     local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
  3143.     local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
  3144.  
  3145.     # we have a CDPATH, so loop on its contents
  3146.     for i in ${CDPATH//:/$'\t'}; do
  3147.         # create an array of matched subdirs
  3148.         k="${#COMPREPLY[@]}"
  3149.         for j in $( compgen -d $i/$cur ); do
  3150.             if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
  3151.                 j="${j}/"
  3152.             fi
  3153.             COMPREPLY[k++]=${j#$i/}
  3154.         done
  3155.     done
  3156.  
  3157.     _filedir -d
  3158.  
  3159.     if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
  3160.         i=${COMPREPLY[0]}
  3161.         if [ "$i" == "$cur" ] && [[ $i != "*/" ]]; then
  3162.         COMPREPLY[0]="${i}/"
  3163.         fi
  3164.     fi
  3165.  
  3166.     return 0
  3167. }
  3168. if shopt -q cdable_vars; then
  3169.     complete -v -F _cd $nospace $filenames cd
  3170. else
  3171.     complete -F _cd $nospace $filenames cd
  3172. fi
  3173.  
  3174. _remove_comp_word()
  3175. {
  3176.     if [[ COMP_CWORD -eq 0 ]]; then
  3177.         return
  3178.     elif [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
  3179.         local old_cw0="${COMP_WORDS[0]}"
  3180.         local new_cw0="${COMP_WORDS[1]}"
  3181.         local old_length="${#COMP_LINE}"
  3182.         COMP_LINE=${COMP_LINE#${old_cw0}}
  3183.         local head=${COMP_LINE:0:${#new_cw0}}
  3184.         local i=1
  3185.         while [[ $head != $new_cw0 ]]; do
  3186.             COMP_LINE=${COMP_LINE:1}
  3187.             head=${COMP_LINE:0:${#new_cw0}}
  3188.             if (( ++i > 10 )); then
  3189.                 break
  3190.             fi
  3191.         done
  3192.         local new_length="${#COMP_LINE}"
  3193.         COMP_POINT=$(( COMP_POINT + new_length - old_length ))
  3194.         
  3195.         COMP_CWORD=$(( COMP_CWORD - 1 ))
  3196.         for (( i=0; i < ${#COMP_WORDS[@]} - 1; ++i )); do
  3197.             COMP_WORDS[i]="${COMP_WORDS[i+1]}"
  3198.         done
  3199.         unset COMP_WORDS[${#COMP_WORDS[@]}-1]
  3200.     else
  3201.         return
  3202.     fi
  3203. }
  3204.  
  3205. # A meta-command completion function for commands like sudo(8), which need to
  3206. # first complete on a command, then complete according to that command's own
  3207. # completion definition - currently not quite foolproof (e.g. mount and umount
  3208. # don't work properly), but still quite useful.
  3209. #
  3210. _command()
  3211. {
  3212.     local cur func cline cspec noglob cmd done i \
  3213.           _COMMAND_FUNC _COMMAND_FUNC_ARGS
  3214.  
  3215.     _remove_comp_word
  3216.     COMPREPLY=()
  3217.     cur=`_get_cword`
  3218.     # If the the first arguments following our meta-command-invoker are
  3219.     # switches, get rid of them. Most definitely not foolproof.
  3220.     done=
  3221.     while [ -z $done ] ; do
  3222.         cmd=${COMP_WORDS[0]}
  3223.         if [[ "$cmd" == -* ]] && [[ $COMP_CWORD -ge 1 ]]; then
  3224.             _remove_comp_word
  3225.         elif [[ "$cmd" == -* ]] && [[ $COMP_CWORD -eq 0 ]]; then
  3226.             return
  3227.         else
  3228.             done=1
  3229.         fi
  3230.     done
  3231.  
  3232.     if [[ $COMP_CWORD -eq 0 ]]; then
  3233.         COMPREPLY=( $( compgen -c -- $cur ) )
  3234.     elif complete -p $cmd &>/dev/null; then
  3235.         cspec=$( complete -p $cmd )
  3236.         if [ "${cspec#* -F }" != "$cspec" ]; then
  3237.             # complete -F <function>
  3238.             #
  3239.             # COMP_CWORD and COMP_WORDS() are not read-only,
  3240.             # so we can set them before handing off to regular
  3241.             # completion routine
  3242.  
  3243.             # get function name
  3244.             func=${cspec#*-F }
  3245.             func=${func%% *}
  3246.             
  3247.             if [[ ${#COMP_WORDS[@]} -ge 2 ]]; then
  3248.                 $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"    "${COMP_WORDS[${#COMP_WORDS[@]}-2]}"
  3249.             else
  3250.                 $func $cmd "${COMP_WORDS[${#COMP_WORDS[@]}-1]}"
  3251.             fi
  3252.  
  3253.             # remove any \: generated by a command that doesn't
  3254.             # default to filenames or dirnames (e.g. sudo chown)
  3255.             # FIXME: I'm pretty sure this does not work!
  3256.             if [ "${cspec#*-o }" != "$cspec" ]; then
  3257.                 cspec=${cspec#*-o }
  3258.                 cspec=${cspec%% *}
  3259.                 if [[ "$cspec" != @(dir|file)names ]]; then
  3260.                     COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
  3261.                 fi
  3262.             fi
  3263.         elif [ -n "$cspec" ]; then
  3264.             cspec=${cspec#complete};
  3265.             cspec=${cspec%%$cmd};
  3266.             COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) );
  3267.         fi
  3268.     fi
  3269.  
  3270.     [ ${#COMPREPLY[@]} -eq 0 ] && _filedir
  3271. }
  3272. complete -F _command $filenames nohup exec nice eval strace time ltrace then \
  3273.     else do vsound command xargs tsocks
  3274.  
  3275. _root_command()
  3276. {
  3277.     PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3
  3278. }
  3279. complete -F _root_command $filenames sudo fakeroot really
  3280.  
  3281. # ant(1) completion
  3282. #
  3283. have ant && {
  3284. _ant()
  3285. {
  3286.     local cur prev buildfile i
  3287.  
  3288.     COMPREPLY=()
  3289.     cur=`_get_cword`
  3290.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3291.  
  3292.     case "$prev" in
  3293.         -buildfile|-f)
  3294.             _filedir 'xml'
  3295.             return 0
  3296.             ;;
  3297.         -logfile)
  3298.             _filedir
  3299.             return 0
  3300.             ;;
  3301.     esac
  3302.  
  3303.     if [[ "$cur" == -* ]]; then
  3304.         # relevant options completion
  3305.         COMPREPLY=( $( compgen -W '-help -projecthelp -version -quiet \
  3306.                    -verbose -debug -emacs -logfile -logger \
  3307.                    -listener -buildfile -f -D -find' -- $cur ) )
  3308.     else
  3309.         # available targets completion
  3310.         # find which buildfile to use
  3311.         buildfile=build.xml
  3312.         for (( i=1; i < COMP_CWORD; i++ )); do
  3313.             if [[ "${COMP_WORDS[i]}" == -buildfile ]]; then
  3314.                 buildfile=${COMP_WORDS[i+1]}
  3315.                 break
  3316.             fi
  3317.         done
  3318.         [ ! -f $buildfile ] && return 0
  3319.  
  3320.         # parse buildfile for targets
  3321.         COMPREPLY=( $( awk -F'"' '/<target name="/ {print $2}' \
  3322.                 $buildfile | grep "^$cur" )
  3323.                 $( awk -F"'" "/<target name='/ "'{print $2}' \
  3324.                 $buildfile | grep "^$cur" )
  3325.                 $( awk -F'"' '/<target [^n]/ {if ($1 ~ /name=/) { print $2 } else if ($3 ~ /name=/) {print $4} else if ($5 ~ /name=/) {print $6}}' \
  3326.                 $buildfile | grep "^$cur" ) )
  3327.     fi
  3328. }
  3329. have complete-ant-cmd.pl && \
  3330.      complete -C complete-ant-cmd.pl -F _ant $filenames ant || \
  3331.      complete -F _ant $filenames ant
  3332. }
  3333.  
  3334. have nslookup &&
  3335. _nslookup()
  3336. {
  3337.     local cur
  3338.  
  3339.     COMPREPLY=()
  3340.     cur=${COMP_WORDS[COMP_CWORD]#-}
  3341.  
  3342.     COMPREPLY=( $( compgen -P '-' -W 'all class= debug d2 domain= \
  3343.                    srchlist= defname search port= querytype= \
  3344.                    type= recurse retry root timeout vc \
  3345.                    ignoretc' -- $cur ) )
  3346. } &&
  3347. complete -F _nslookup nslookup
  3348.  
  3349. # mysqladmin(1) completion
  3350. #
  3351. have mysqladmin &&
  3352. _mysqladmin()
  3353. {
  3354.     local cur prev
  3355.  
  3356.     COMPREPLY=()
  3357.     cur=`_get_cword`
  3358.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3359.  
  3360.     case "$prev" in
  3361.     -u)
  3362.         COMPREPLY=( $( compgen -u -- $cur ) )
  3363.         return 0
  3364.         ;;
  3365.     *)
  3366.         ;;
  3367.     esac
  3368.  
  3369.     COMPREPLY=( $( compgen -W '-# -f -? -C -h -p -P -i -r -E -s -S -t -u \
  3370.                           -v -V -w' -- $cur ) )
  3371.  
  3372.     COMPREPLY=( "${COMPREPLY[@]}" \
  3373.             $( compgen -W 'create drop extended-status flush-hosts \
  3374.                    flush-logs flush-status flush-tables \
  3375.                    flush-threads flush-privileges kill \
  3376.                    password ping processlist reload refresh \
  3377.                    shutdown status variables version' \
  3378.                -- $cur ) )
  3379. } &&
  3380. complete -F _mysqladmin mysqladmin
  3381.  
  3382. # gzip(1) completion
  3383. #
  3384. have gzip &&
  3385. _gzip()
  3386. {
  3387.     local cur prev xspec IFS=$'\t\n'
  3388.  
  3389.     COMPREPLY=()
  3390.     cur=`_get_cword`
  3391.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3392.  
  3393.     if [[ "$cur" == -* ]]; then
  3394.         COMPREPLY=( $( compgen -W '-c -d -f \
  3395.             -h -l -L -n -N -q -r -S -t -v -V \
  3396.             -1 -2 -3 -4 -5 -6 -7 -8 -9 \
  3397.             --stdout --decompress --force --help --list \
  3398.             --license --no-name --name --quiet --recursive \
  3399.             --suffix --test --verbose --version --fast \
  3400.             --best' -- $cur ) )
  3401.         return 0
  3402.     fi
  3403.  
  3404.     xspec="*.?(t)gz"
  3405.     if [[ "$prev" == --* ]]; then
  3406.         [[ "$prev" == --decompress || \
  3407.             "$prev" == --list || \
  3408.             "$prev" == --test ]] && xspec="!"$xspec
  3409.         [[ "$prev" == --force ]] && xspec=
  3410.     elif [[ "$prev" == -* ]]; then
  3411.         [[ "$prev" == -*[dlt]* ]] && xspec="!"$xspec
  3412.         [[ "$prev" == -*f* ]] && xspec=
  3413.     elif [ "$prev" = '>' ]; then
  3414.         xspec=
  3415.     elif [ "$prev" = '<' ]; then
  3416.         xspec=
  3417.     fi
  3418.  
  3419.     _expand || return 0
  3420.  
  3421.     COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
  3422.             $( compgen -d -- $cur ) )
  3423. } &&
  3424. complete -F _gzip $filenames gzip
  3425.  
  3426. # bzip2(1) completion
  3427. #
  3428. have bzip2 &&
  3429. _bzip2()
  3430. {
  3431.     local cur prev xspec IFS=$'\t\n'
  3432.  
  3433.     COMPREPLY=()
  3434.     cur=`_get_cword`
  3435.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3436.  
  3437.     if [[ "$cur" == -* ]]; then
  3438.         COMPREPLY=( $( compgen -W '-c -d -f -h -k -L -q -s \
  3439.             -t -v -V -z -1 -2 -3 -4 -5 -6 -7 -8 -9 \
  3440.             --help --decompress --compress --keep --force \
  3441.             --test --stdout --quiet --verbose --license \
  3442.             --version --small --fast --best' -- $cur ) )
  3443.         return 0
  3444.     fi
  3445.  
  3446.     xspec="*.bz2"
  3447.     if [[ "$prev" == --* ]]; then
  3448.         [[ "$prev" == --decompress || \
  3449.             "$prev" == --list || \
  3450.             "$prev" == --test ]] && xspec="!"$xspec
  3451.         [[ "$prev" == --compress ]] && xspec=
  3452.     elif [[ "$prev" == -* ]]; then
  3453.         [[ "$prev" == -*[dt]* ]] && xspec="!"$xspec
  3454.         [[ "$prev" == -*z* ]] && xspec=
  3455.     fi
  3456.  
  3457.     _expand || return 0
  3458.  
  3459.     COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
  3460.             $( compgen -d -- $cur ) )
  3461. } &&
  3462. complete -F _bzip2 $filenames bzip2
  3463.  
  3464. # openssl(1) completion
  3465. #
  3466. have openssl && {
  3467. _openssl_sections()
  3468. {
  3469.     local config
  3470.  
  3471.     config=/etc/ssl/openssl.cnf
  3472.     [ ! -f $config ] && config=/usr/share/ssl/openssl.cnf
  3473.     for (( i=2; i < COMP_CWORD; i++ )); do
  3474.         if [[ "${COMP_WORDS[i]}" == -config ]]; then
  3475.             config=${COMP_WORDS[i+1]}
  3476.             break
  3477.         fi
  3478.     done
  3479.     [ ! -f $config ] && return 0
  3480.  
  3481.     COMPREPLY=( $( awk '/\[.*\]/ {print $2} ' $config | grep "^$cur" ) )
  3482. }
  3483.  
  3484. _openssl()
  3485. {
  3486.     local cur prev
  3487.  
  3488.     COMPREPLY=()
  3489.     cur=`_get_cword`
  3490.  
  3491.     if [ $COMP_CWORD -eq 1 ]; then
  3492.         COMPREPLY=( $( compgen -W 'asn1parse ca ciphers crl crl2pkcs7 \
  3493.             dgst dh dhparam dsa dsaparam enc errstr gendh gendsa \
  3494.             genrsa nseq passwd pkcs12 pkcs7 pkcs8 rand req rsa \
  3495.             rsautl s_client s_server s_time sess_id smime speed \
  3496.             spkac verify version x509 md2 md4 md5 mdc2 rmd160 sha \
  3497.             sha1 base64 bf bf-cbc bf-cfb bf-ecb bf-ofb cast \
  3498.             cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb des \
  3499.             des-cbc des-cfb des-ecb des-ede des-ede-cbc \
  3500.             des-ede-cfb des-ede-ofb des-ede3 des-ede3-cbc \
  3501.             des-ede3-cfb des-ede3-ofb des-ofb des3 desx rc2 \
  3502.             rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb \
  3503.             rc4 rc4-40' -- $cur ) )
  3504.     else
  3505.         prev=${COMP_WORDS[COMP_CWORD-1]}
  3506.         case ${COMP_WORDS[1]} in
  3507.             asn1parse)
  3508.                 case $prev in
  3509.                     -inform)
  3510.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3511.                         return 0
  3512.                         ;;
  3513.                     -@(in|out|oid))
  3514.                         _filedir
  3515.                         return 0
  3516.                         ;;
  3517.                     esac
  3518.  
  3519.                 if [[ "$cur" == -* ]]; then
  3520.                     COMPREPLY=( $( compgen -W '-inform -in -out -noout -offset \
  3521.                         -length -i -oid -strparse' -- $cur ) )
  3522.                 fi
  3523.                 ;;
  3524.             ca)
  3525.                 case $prev in
  3526.                     -@(config|revoke|cert|in|out|spkac|ss_cert))
  3527.                         _filedir
  3528.                         return 0
  3529.                         ;;
  3530.                     -outdir)
  3531.                         _filedir -d
  3532.                         return 0
  3533.                         ;;
  3534.                     -@(name|crlexts|extensions))
  3535.                         _openssl_sections
  3536.                         return 0
  3537.                         ;;
  3538.                 esac
  3539.  
  3540.                 if [[ "$cur" == -* ]]; then
  3541.                     COMPREPLY=( $( compgen -W '-verbose -config -name \
  3542.                         -gencrl -revoke -crldays -crlhours -crlexts \
  3543.                         -startdate -enddate -days -md -policy -keyfile \
  3544.                         -key -passin -cert -in -out -notext -outdir \
  3545.                         -infiles -spkac -ss_cert -preserveDN -batch \
  3546.                         -msie_hack -extensions' -- $cur ) )
  3547.                 fi
  3548.                 ;;
  3549.             ciphers)
  3550.                 if [[ "$cur" == -* ]]; then
  3551.                     COMPREPLY=( $( compgen -W '-v -ssl2 -ssl3 -tls1' -- $cur ) )
  3552.                 fi
  3553.                 ;;
  3554.             crl)
  3555.                 case $prev in
  3556.                     -@(in|out)form)
  3557.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3558.                         return 0
  3559.                         ;;
  3560.                     -@(in|out|CAfile))
  3561.                         _filedir
  3562.                         return 0
  3563.                         ;;
  3564.                     -CAPath)
  3565.                         _filedir -d
  3566.                         return 0
  3567.                         ;;
  3568.                 esac
  3569.  
  3570.                 if [[ "$cur" == -* ]]; then
  3571.                     COMPREPLY=( $( compgen -W '-inform -outform -text -in -out -noout \
  3572.                         -hash -issuer -lastupdate -nextupdate -CAfile -CApath' -- $cur ) )
  3573.                 fi
  3574.                 ;;
  3575.             crl2pkcs7)
  3576.                 case $prev in
  3577.                     -@(in|out)form)
  3578.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3579.                         return 0
  3580.                         ;;
  3581.                     -@(in|out))
  3582.                         _filedir
  3583.                         return 0
  3584.                         ;;
  3585.                 esac
  3586.  
  3587.                 if [[ "$cur" == -* ]]; then
  3588.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs' -- $cur ) )
  3589.                 fi
  3590.                 ;;
  3591.             dgst)
  3592.                 case $prev in
  3593.                     -@(out|sign|verify|prvrify|signature))
  3594.                         _filedir
  3595.                         return 0
  3596.                         ;;
  3597.                 esac
  3598.  
  3599.                 if [[ "$cur" == -* ]]; then
  3600.                     COMPREPLY=( $( compgen -W '-md5 -md4 -md2 -sha1 -sha -mdc2 -ripemd160 -dss1 \
  3601.                         -c -d -hex -binary -out -sign -verify -prverify -signature' -- $cur ) )
  3602.                 else
  3603.                         _filedir
  3604.                 fi
  3605.                    ;;
  3606.             dsa)
  3607.                 case $prev in
  3608.                     -@(in|out)form)
  3609.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3610.                         return 0
  3611.                         ;;
  3612.                     -@(in|out))
  3613.                         _filedir
  3614.                         return 0
  3615.                         ;;
  3616.                 esac
  3617.  
  3618.                 if [[ "$cur" == -* ]]; then
  3619.                     COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout -des -des3 -idea -text -noout \
  3620.                         -modulus -pubin -pubout' -- $cur ) )
  3621.                 fi
  3622.                 ;;
  3623.             dsaparam)
  3624.                 case $prev in
  3625.                     -@(in|out)form)
  3626.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3627.                         return 0
  3628.                         ;;
  3629.                     -@(in|out|rand))
  3630.                         _filedir
  3631.                         return 0
  3632.                         ;;
  3633.                 esac
  3634.  
  3635.                 if [[ "$cur" == -* ]]; then
  3636.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -noout \
  3637.                         -text -C -rand -genkey' -- $cur ) )
  3638.                 fi
  3639.                 ;;
  3640.             enc)
  3641.                 case $prev in
  3642.                     -@(in|out|kfile))
  3643.                         _filedir
  3644.                         return 0
  3645.                         ;;
  3646.                 esac
  3647.  
  3648.                 if [[ "$cur" == -* ]]; then
  3649.                     COMPREPLY=( $( compgen -W '-ciphername -in -out -pass \
  3650.                         -e -d -a -A -k -kfile -S -K -iv -p -P -bufsize -debug' -- $cur ) )
  3651.                 fi
  3652.                 ;;
  3653.             dhparam)
  3654.                 case $prev in
  3655.                     -@(in|out)form)
  3656.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3657.                         return 0
  3658.                         ;;
  3659.                     -@(in|out|rand))
  3660.                         _filedir
  3661.                         return 0
  3662.                         ;;
  3663.                 esac
  3664.  
  3665.                 if [[ "$cur" == -* ]]; then
  3666.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -dsaparam -noout \
  3667.                         -text -C -2 -5 -rand' -- $cur ) )
  3668.                 fi
  3669.                 ;;
  3670.             gendsa)
  3671.                 case $prev in
  3672.                     -@(out|rand))
  3673.                         _filedir
  3674.                         return 0
  3675.                         ;;
  3676.                 esac
  3677.  
  3678.                 if [[ "$cur" == -* ]]; then
  3679.                     COMPREPLY=( $( compgen -W '-out -des -des3 -idea -rand' -- $cur ) )
  3680.                 else
  3681.                         _filedir
  3682.                 fi
  3683.                 ;;
  3684.             genrsa)
  3685.                 case $prev in
  3686.                     -@(out|rand))
  3687.                         _filedir
  3688.                         return 0
  3689.                         ;;
  3690.                 esac
  3691.  
  3692.                 if [[ "$cur" == -* ]]; then
  3693.                     COMPREPLY=( $( compgen -W '-out -passout -des -des3 -idea -f4 -3 -rand' -- $cur ) )
  3694.                 fi
  3695.                 ;;
  3696.             pkcs7)
  3697.                 case $prev in
  3698.                     -@(in|out)form)
  3699.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3700.                         return 0
  3701.                         ;;
  3702.                     -@(in|out))
  3703.                         _filedir
  3704.                         return 0
  3705.                         ;;
  3706.                 esac
  3707.  
  3708.                 if [[ "$cur" == -* ]]; then
  3709.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -print_certs -text -noout' -- $cur ) )
  3710.                 fi
  3711.                 ;;
  3712.             rand)
  3713.                 case $prev in
  3714.                     -@(out|rand))
  3715.                         _filedir
  3716.                         return 0
  3717.                         ;;
  3718.                 esac
  3719.  
  3720.                 if [[ "$cur" == -* ]]; then
  3721.                     COMPREPLY=( $( compgen -W '-out -rand -base64' -- $cur ) )
  3722.                 fi
  3723.                 ;;
  3724.             req)
  3725.                 case "$prev" in
  3726.                     -@(in|out|key)form)
  3727.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3728.                         return 0
  3729.                         ;;
  3730.  
  3731.                     -@(in|out|rand|key|keyout|config))
  3732.                         _filedir
  3733.                         return 0
  3734.                         ;;
  3735.                     -extensions)
  3736.                         _openssl_sections
  3737.                         return 0
  3738.                         ;;
  3739.                 esac
  3740.  
  3741.                 if [[ "$cur" == -* ]]; then
  3742.                     COMPREPLY=( $( compgen -W '-inform -outform -in \
  3743.                         -passin -out -passout -text -noout -verify \
  3744.                         -modulus -new -rand -newkey -newkey -nodes \
  3745.                         -key -keyform -keyout -md5 -sha1 -md2 -mdc2 \
  3746.                         -config -x509 -days -asn1-kludge -newhdr \
  3747.                         -extensions -reqexts section' -- $cur ) )
  3748.                 fi
  3749.                 ;;
  3750.             rsa)
  3751.                 case $prev in
  3752.                     -@(in|out)form)
  3753.                         COMPREPLY=( $( compgen -W 'DER NET PEM' -- $cur ) )
  3754.                         return 0
  3755.                         ;;
  3756.                     -@(in|out))
  3757.                         _filedir
  3758.                         return 0
  3759.                         ;;
  3760.                 esac
  3761.  
  3762.                 if [[ "$cur" == -* ]]; then
  3763.                     COMPREPLY=( $( compgen -W '-inform -outform -in -passin -out -passout \
  3764.                         -sgckey -des -des3 -idea -text -noout -modulus -check -pubin \
  3765.                         -pubout -engine' -- $cur ) )
  3766.                 fi
  3767.                 ;;
  3768.             rsautl)
  3769.                 case $prev in
  3770.                     -@(in|out|inkey))
  3771.                         _filedir
  3772.                         return 0
  3773.                         ;;
  3774.                 esac
  3775.  
  3776.                 if [[ "$cur" == -* ]]; then
  3777.                     COMPREPLY=( $( compgen -W '-in -out -inkey -pubin -certin -sign -verify \
  3778.                         -encrypt -decrypt -pkcs -ssl -raw -hexdump -asn1parse' -- $cur ) )
  3779.                 fi
  3780.                 ;;
  3781.             s_client)
  3782.                 case $prev in
  3783.                     -connect)
  3784.                         _known_hosts
  3785.                         return 0
  3786.                         ;;
  3787.                     -@(cert|key|CAfile|rand))
  3788.                         _filedir
  3789.                         return 0
  3790.                         ;;
  3791.                     -CApath)
  3792.                         _filedir -d
  3793.                         return 0
  3794.                         ;;
  3795.                 esac
  3796.  
  3797.                 if [[ "$cur" == -* ]]; then
  3798.                     COMPREPLY=( $( compgen -W '-connect -verify -cert -key -CApath -CAfile \
  3799.                         -reconnect -pause -showcerts -debug -msg -nbio_test -state -nbio \
  3800.                         -crlf -ign_eof -quiet -ssl2 -ssl3 -tls1 -no_ssl2 -no_ssl3 -no_tls1 \
  3801.                         -bugs -cipher -starttls -engine -rand' -- $cur ) )
  3802.                 fi
  3803.                 ;;
  3804.             s_server)
  3805.                 case $prev in
  3806.                     -@(cert|key|dcert|dkey|dhparam|CAfile|rand))
  3807.                         _filedir
  3808.                         return 0
  3809.                         ;;
  3810.                     -CApath)
  3811.                         _filedir -d
  3812.                         return 0
  3813.                         ;;
  3814.                 esac
  3815.  
  3816.                 if [[ "$cur" == -* ]]; then
  3817.                     COMPREPLY=( $( compgen -W '-accept -context -verify -Verify -cert -key \
  3818.                          -dcert -dkey -dhparam -nbio -nbio_test -crlf -debug -msg -state -CApath \
  3819.                          -CAfile -nocert -cipher -quiet -no_tmp_rsa -ssl2 -ssl3 -tls1 -no_ssl2 \
  3820.                          -no_ssl3 -no_tls1 -no_dhe -bugs -hack -www -WWW -HTTP -engine -id_prefix \
  3821.                          -rand' -- $cur ) )
  3822.                  fi
  3823.                  ;;
  3824.             s_time)
  3825.                 case $prev in
  3826.                     -connect)
  3827.                         _known_hosts
  3828.                         return 0
  3829.                         ;;
  3830.                     -@(cert|key|CAfile))
  3831.                         _filedir
  3832.                         return 0
  3833.                         ;;
  3834.                     -CApath)
  3835.                         _filedir -d
  3836.                         return 0
  3837.                         ;;
  3838.                 esac
  3839.  
  3840.                 if [[ "$cur" == -* ]]; then
  3841.                     COMPREPLY=( $( compgen -W '-connect -www -cert -key -CApath -CAfile -reuse \
  3842.                         -new -verify -nbio -time -ssl2 -ssl3 -bugs -cipher' -- $cur ) )
  3843.                 fi
  3844.                 ;;
  3845.  
  3846.             sess_id)
  3847.                 case $prev in
  3848.                     -@(in|out)form)
  3849.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3850.                         return 0
  3851.                         ;;
  3852.                     -@(in|out))
  3853.                         _filedir
  3854.                         return 0
  3855.                         ;;
  3856.                 esac
  3857.  
  3858.  
  3859.                 if [[ "$cur" == -* ]]; then
  3860.                     COMPREPLY=( $( compgen -W '-inform -outform -in -out -text -noout \
  3861.                         -context ID' -- $cur ) )
  3862.                 fi
  3863.                 ;;
  3864.             smime)
  3865.                 case $prev in
  3866.                     -@(in|out)form)
  3867.                         COMPREPLY=( $( compgen -W 'SMIME DER PEM' -- $cur ) )
  3868.                         return 0
  3869.                         ;;
  3870.                     -@(in|out|certfile|signer|recip|inkey|content|rand))
  3871.                         _filedir
  3872.                         return 0
  3873.                         ;;
  3874.                 esac
  3875.  
  3876.                 if [[ "$cur" == -* ]]; then
  3877.                     COMPREPLY=( $( compgen -W '-encrypt -decrypt -sign -verify -pk7out -des -des3 \
  3878.                         -rc2-40 -rc2-64 -rc2-128 -aes128 -aes192 -aes256 -in -certfile -signer \
  3879.                         -recip -inform -passin -inkey -out -outform -content -to -from -subject \
  3880.                         -text -rand' -- $cur ) )
  3881.                 else
  3882.                         _filedir
  3883.                 fi
  3884.                 ;;
  3885.             speed)
  3886.                 if [[ "$cur" == -* ]]; then
  3887.                     COMPREPLY=( $( compgen -W '-engine' -- $cur ) )
  3888.                 else
  3889.                     COMPREPLY=( $( compgen -W 'md2 mdc2 md5 hmac sha1 rmd160 idea-cbc \
  3890.                         rc2-cbc rc5-cbc bf-cbc des-cbc des-ede3 rc4 rsa512 rsa1024 rsa2048 \
  3891.                         rsa4096 dsa512 dsa1024 dsa2048 idea rc2 des rsa blowfish' -- $cur ) )
  3892.                 fi
  3893.                 ;;
  3894.             verify)
  3895.                 case $prev in
  3896.                     -@(CAfile|untrusted))
  3897.                         _filedir
  3898.                         return 0
  3899.                         ;;
  3900.                     -CApath)
  3901.                         _filedir -d
  3902.                         return 0
  3903.                         ;;
  3904.                 esac
  3905.  
  3906.                 if [[ "$cur" == -* ]]; then
  3907.                     COMPREPLY=( $( compgen -W '-CApath -CAfile -purpose -untrusted -help -issuer_checks \
  3908.                         -verbose -certificates' -- $cur ) )
  3909.                 else
  3910.                         _filedir
  3911.                 fi
  3912.                 ;;
  3913.             x509)
  3914.                 case "$prev" in
  3915.                     -@(in|out|CA|CAkey|CAserial|extfile))
  3916.                         _filedir
  3917.                         return 0
  3918.                         ;;
  3919.                     -@(in|out)form)
  3920.                         COMPREPLY=( $( compgen -W 'DER PEM NET' -- $cur ) )
  3921.                         return 0
  3922.                         ;;
  3923.                     -@(key|CA|CAkey)form)
  3924.                         COMPREPLY=( $( compgen -W 'DER PEM' -- $cur ) )
  3925.                         return 0
  3926.                         ;;
  3927.                     -extensions)
  3928.                         _openssl_sections
  3929.                         return 0
  3930.                         ;;
  3931.                 esac
  3932.  
  3933.                 if [[ "$cur" == -* ]]; then
  3934.                     COMPREPLY=( $( compgen -W '-inform -outform \
  3935.                         -keyform -CAform -CAkeyform -in -out \
  3936.                         -serial -hash -subject -issuer -nameopt \
  3937.                         -email -startdate -enddate -purpose \
  3938.                         -dates -modulus -fingerprint -alias \
  3939.                         -noout -trustout -clrtrust -clrreject \
  3940.                         -addtrust -addreject -setalias -days \
  3941.                         -set_serial -signkey -x509toreq -req \
  3942.                         -CA -CAkey -CAcreateserial -CAserial \
  3943.                         -text -C -md2 -md5 -sha1 -mdc2 -clrext \
  3944.                         -extfile -extensions -engine' -- $cur ) )
  3945.                 fi
  3946.                 ;;
  3947.             @(md5|md4|md2|sha1|sha|mdc2|ripemd160))
  3948.                 if [[ "$cur" == -* ]]; then
  3949.                     COMPREPLY=( $( compgen -W '-c -d' -- $cur ) )
  3950.                 else
  3951.                         _filedir
  3952.                 fi
  3953.                 ;;
  3954.         esac
  3955.     fi
  3956.  
  3957.     return 0
  3958. }
  3959. complete -F _openssl $default openssl
  3960. }
  3961.  
  3962. # screen(1) completion
  3963. #
  3964. have screen &&
  3965. _screen()
  3966. {
  3967.     local cur prev preprev
  3968.  
  3969.     COMPREPLY=()
  3970.     cur=`_get_cword`
  3971.     prev=${COMP_WORDS[COMP_CWORD-1]}
  3972.  
  3973.     [ "$COMP_CWORD" -ge 2 ] && preprev=${COMP_WORDS[COMP_CWORD-2]}
  3974.  
  3975.     if [ "$preprev" = "-d" -o "$preprev" = "-D" -a "$prev" = "-r" -o \
  3976.          "$prev" = "-R" ]; then
  3977.         # list all
  3978.         COMPREPLY=( $( command screen -ls | \
  3979.                 sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*$|\1|p' ) )
  3980.     else
  3981.         case "$prev" in
  3982.         -[rR])
  3983.             # list detached
  3984.             COMPREPLY=( $( command screen -ls | \
  3985.                     sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Detached.*$|\1|p' ) )
  3986.             ;;
  3987.         -[dDx])
  3988.             # list attached
  3989.             COMPREPLY=( $( command screen -ls | \
  3990.                     sed -ne 's|^['$'\t'']\+\('$cur'[0-9]\+\.[^'$'\t'']\+\).*Attached.*$|\1|p' ) )
  3991.             ;;
  3992.         -s)
  3993.             # shells
  3994.             COMPREPLY=( $( grep ^${cur:-[^#]} /etc/shells ) )
  3995.             ;;
  3996.         *)
  3997.             ;;
  3998.         esac
  3999.     fi
  4000.  
  4001.     return 0
  4002. } &&
  4003. complete -F _screen $default screen
  4004.  
  4005. # lftp(1) bookmark completion
  4006. #
  4007. have lftp &&
  4008. _lftp()
  4009. {
  4010.     local cur
  4011.  
  4012.     COMPREPLY=()
  4013.     cur=`_get_cword`
  4014.  
  4015.     if [ $COMP_CWORD -eq 1 ] && [ -f ~/.lftp/bookmarks ]; then
  4016.         COMPREPLY=( $( compgen -W '$( sed -ne "s/^\(.*\)'$'\t''.*$/\1/p" \
  4017.                ~/.lftp/bookmarks )' -- $cur ) )
  4018.     fi
  4019.  
  4020.     return 0
  4021. } &&
  4022. complete -F _lftp $default lftp
  4023.  
  4024. # ncftp(1) bookmark completion
  4025. #
  4026. have ncftp &&
  4027. _ncftp()
  4028. {
  4029.     local cur
  4030.  
  4031.     COMPREPLY=()
  4032.     cur=`_get_cword`
  4033.  
  4034.     if [ $COMP_CWORD -eq 1 ] && [ -f ~/.ncftp/bookmarks ]; then
  4035.         COMPREPLY=( $( compgen -W '$( sed -ne "s/^\([^,]\{1,\}\),.*$/\1/p" \
  4036.                ~/.ncftp/bookmarks )' -- $cur ) )
  4037.     fi
  4038.  
  4039.     return 0
  4040. } &&
  4041. complete -F _ncftp $default ncftp
  4042.  
  4043. # gdb(1) completion
  4044. #
  4045. have gdb &&
  4046. _gdb()
  4047. {
  4048.     local cur prev
  4049.  
  4050.     COMPREPLY=()
  4051.     cur=`_get_cword`
  4052.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4053.  
  4054.     if [ $COMP_CWORD -eq 1 ]; then
  4055.         local IFS
  4056.         if [[ "$cur" == */* ]]; then
  4057.             # compgen -c works as expected if $cur contains any slashes.
  4058.             IFS=$'\n'
  4059.             COMPREPLY=( $( PATH="$PATH:." compgen -d -c -- "$cur" ) )
  4060.         else
  4061.             # otherwise compgen -c contains Bash's built-in commands,
  4062.             # functions and aliases. Thus we need to retrieve the program
  4063.             # names manually.
  4064.             IFS=":"
  4065.             local path_array=( $(echo "$PATH") )
  4066.             IFS=$'\n'
  4067.             COMPREPLY=( $( compgen -d -W '$(find "${path_array[@]}" . \
  4068.                 -mindepth 1 -maxdepth 1 -not -type d -executable -printf "%f\\n")' \
  4069.                 -- "$cur" ) )
  4070.         fi
  4071.     elif [ $COMP_CWORD -eq 2 ]; then
  4072.         prev=${prev##*/}
  4073.         COMPREPLY=( $( compgen -fW "$( command ps axo comm,pid | \
  4074.                 awk '{if ($1 ~ /^'"$prev"'/) print $2}' ) )" \
  4075.                 -- "$cur" ) )
  4076.     fi
  4077. } &&
  4078. complete -F _gdb $default gdb
  4079.  
  4080. # Postgresql completion
  4081. #
  4082. have psql && {
  4083. _pg_databases()
  4084. {
  4085.     return
  4086.     COMPREPLY=( $( psql -l 2>/dev/null | \
  4087.             sed -e '1,/^-/d' -e '/^(/,$d' | \
  4088.             awk '{print $1}' | grep "^$cur" ) )
  4089. }
  4090.  
  4091. _pg_users()
  4092. {
  4093.     #COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \
  4094.     #        grep "^ $cur" ) )
  4095.     #[ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- $cur ) )
  4096.     COMPREPLY=( $( compgen -u -- $cur ) )
  4097. }
  4098.  
  4099. # createdb(1) completion
  4100. #
  4101. _createdb()
  4102. {
  4103.     local cur prev
  4104.  
  4105.     COMPREPLY=()
  4106.     cur=`_get_cword`
  4107.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4108.  
  4109.     case "$prev" in
  4110.     -@(h|-host=))
  4111.         _known_hosts
  4112.         return 0
  4113.         ;;
  4114.     -@(U|-username=))
  4115.         _pg_users
  4116.         return 0
  4117.         ;;
  4118.     esac
  4119.  
  4120.     if [[ "$cur" == -* ]]; then
  4121.         COMPREPLY=( $( compgen -W '-D -T -E -h -p -U -W -e -q \
  4122.             --location= --template= --encoding= --host= --port= \
  4123.             --username= --password --echo --quiet --help' -- $cur ))
  4124.     else
  4125.         _pg_databases
  4126.     fi
  4127. }
  4128. complete -F _createdb $default createdb
  4129.  
  4130. # dropdb(1) completion
  4131. #
  4132. _dropdb()
  4133. {
  4134.     local cur prev
  4135.  
  4136.     COMPREPLY=()
  4137.     cur=`_get_cword`
  4138.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4139.  
  4140.     case "$prev" in
  4141.     -@(h|-host=))
  4142.         _known_hosts
  4143.         return 0
  4144.         ;;
  4145.     -@(U|-username=))
  4146.         _pg_users
  4147.         return 0
  4148.         ;;
  4149.     esac
  4150.  
  4151.     if [[ "$cur" == -* ]]; then
  4152.         COMPREPLY=( $( compgen -W '-h -p -U -W -e -q \
  4153.                 --host= --port= --username= --password \
  4154.                 --interactive --echo --quiet --help' -- $cur ) )
  4155.     else
  4156.         _pg_databases
  4157.     fi
  4158. }
  4159. complete -F _dropdb $default dropdb
  4160.  
  4161. # psql(1) completion
  4162. #
  4163. _psql()
  4164. {
  4165.     local cur prev
  4166.  
  4167.     COMPREPLY=()
  4168.     cur=`_get_cword`
  4169.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4170.  
  4171.     case "$prev" in
  4172.     -h|--host)
  4173.         _known_hosts
  4174.         return 0
  4175.         ;;
  4176.     -U|--username)
  4177.         _pg_users
  4178.         return 0
  4179.         ;;
  4180.     -d|--dbname)
  4181.         _pg_databases
  4182.         return 0
  4183.         ;;
  4184.     -@(o|f)|--output|--file)
  4185.         _filedir
  4186.         return 0
  4187.         ;;
  4188.     esac
  4189.  
  4190.     if [[ "$cur" == -* ]]; then
  4191.         # return list of available options
  4192.         COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \
  4193.             -c --command -d --dbname -e --echo-queries \
  4194.             -E --echo-hidden -f --file -F --filed-separator \
  4195.             -h --host -H --html -l --list -n -o --output \
  4196.             -p --port -P --pset -q -R --record-separator \
  4197.             -s --single-step -S --single-line -t --tuples-only \
  4198.             -T --table-attr -U --username -v --variable \
  4199.             -V --version -W --password -x --expanded -X --nopsqlrc \
  4200.             -? --help ' -- $cur ) )
  4201.     else
  4202.         # return list of available databases
  4203.         _pg_databases
  4204.     fi
  4205. }
  4206. complete -F _psql $default psql
  4207. }
  4208.  
  4209. _longopt()
  4210. {
  4211.     local cur opt
  4212.  
  4213.     cur=`_get_cword`
  4214.  
  4215.     if [[ "$cur" == --*=* ]]; then
  4216.         opt=${cur%%=*}
  4217.         # cut backslash that gets inserted before '=' sign
  4218.         opt=${opt%\\*}
  4219.         cur=${cur#*=}
  4220.         _filedir
  4221.         COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur))
  4222.         return 0
  4223.     fi
  4224.  
  4225.     if [[ "$cur" == -* ]]; then
  4226.         COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \
  4227.                 -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \
  4228.                    command grep "^$cur" | sort -u ) )
  4229.     elif [[ "$1" == rmdir ]]; then
  4230.         _filedir -d
  4231.     else
  4232.         _filedir
  4233.     fi
  4234. }
  4235. # makeinfo and texi2dvi are defined elsewhere.
  4236. for i in a2ps autoconf automake bc gprof ld nm objcopy objdump readelf strip \
  4237.      bison cpio diff patch enscript cp df dir du ln ls mkfifo mknod mv rm \
  4238.      touch vdir awk gperf grep grub indent less m4 sed shar date \
  4239.      tee who texindex cat csplit cut expand fmt fold head \
  4240.      md5sum nl od paste pr ptx sha1sum sort split tac tail tr unexpand \
  4241.      uniq wc ldd bash id irb mkdir rmdir; do
  4242.   have $i && complete -F _longopt $filenames $i
  4243. done
  4244.  
  4245. # These commands use filenames, so '-o filenames' is not needed.
  4246. for i in env netstat seq uname units wget; do
  4247.   have $i && complete -F _longopt $default $i
  4248. done
  4249. unset i
  4250.  
  4251. # gcc(1) completion
  4252. #
  4253. # The only unusual feature is that we don't parse "gcc --help -v" output
  4254. # directly, because that would include the options of all the other backend
  4255. # tools (linker, assembler, preprocessor, etc) without any indication that
  4256. # you cannot feed such options to the gcc driver directly.  (For example, the
  4257. # linker takes a -z option, but you must type -Wl,-z for gcc.)  Instead, we
  4258. # ask the driver ("g++") for the name of the compiler ("cc1"), and parse the
  4259. # --help output of the compiler.
  4260. #
  4261. have gcc &&
  4262. _gcc()
  4263. {
  4264.     local cur cc backend
  4265.  
  4266.     COMPREPLY=()
  4267.     cur=`_get_cword`
  4268.  
  4269.     _expand || return 0
  4270.  
  4271.     case "$1" in
  4272.     gcj)
  4273.         backend=jc1
  4274.         ;;
  4275.     gpc)
  4276.         backend=gpc1
  4277.         ;;
  4278.     *77)
  4279.         backend=f771
  4280.         ;;
  4281.     *)
  4282.         backend=cc1    # (near-)universal backend
  4283.         ;;
  4284.     esac
  4285.  
  4286.     if [[ "$cur" == -* ]]; then
  4287.         cc=$( $1 -print-prog-name=$backend )
  4288.         # sink stderr:
  4289.         # for C/C++/ObjectiveC it's useless
  4290.         # for FORTRAN/Java it's an error
  4291.         COMPREPLY=( $( $cc --help 2>/dev/null | tr '\t' ' ' | \
  4292.                    sed -e '/^  *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
  4293.                    command grep "^$cur" | sort -u ) )
  4294.     else
  4295.         _filedir
  4296.     fi
  4297. } &&
  4298. complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc
  4299. [ $UNAME = GNU -o $UNAME = Linux -o $UNAME = Cygwin ] && \
  4300. [ -n "${have:-}" ] && complete $filenames -F _gcc cc
  4301.  
  4302. # Linux cardctl(8) completion
  4303. #
  4304. have cardctl &&
  4305. _cardctl()
  4306. {
  4307.     local cur
  4308.  
  4309.     COMPREPLY=()
  4310.     cur=`_get_cword`
  4311.  
  4312.     if [ $COMP_CWORD -eq 1 ]; then
  4313.         COMPREPLY=( $( compgen -W 'status config ident suspend \
  4314.                        resume reset eject insert scheme' \
  4315.                    -- $cur ) )
  4316.     fi
  4317. } &&
  4318. complete -F _cardctl cardctl
  4319.  
  4320. # This function is required by _dpkg() and _dpkg-reconfigure()
  4321. #
  4322. # TODO: Ubuntu (and Debian) folks removed the "have grep-status" part. In my Debian I got it,
  4323. #       and I believe it's ok if we leave it like it is now. Was that removed because
  4324. #       of Ubuntu's (and Debian's? :() inner weirdness? :) -- David (hanska-guest)
  4325. have dpkg && {
  4326. #have grep-status && {
  4327. #_comp_dpkg_installed_packages()
  4328. #{
  4329. #    grep-status -P -e "^$1" -a -FStatus 'install ok installed' -n -s Package
  4330. #}
  4331. #} || {
  4332. _comp_dpkg_installed_packages()
  4333. {
  4334.     grep -A 1 "Package: $1" /var/lib/dpkg/status | \
  4335.         grep -B 1 -E "ok installed|half-installed|unpacked| \
  4336.                     half-configured|config-files" | \
  4337.         grep "Package: $1" | cut -d\  -f2
  4338. }
  4339. #}
  4340.  
  4341. # Debian dpkg(8) completion
  4342. #
  4343. _dpkg()
  4344. {
  4345.     local cur prev i
  4346.  
  4347.     COMPREPLY=()
  4348.     cur=`_get_cword`
  4349.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4350.     i=$COMP_CWORD
  4351.  
  4352.     _expand || return 0
  4353.  
  4354.     # find the last option flag
  4355.     if [[ $cur != -* ]]; then
  4356.         while [[ $prev != -* && $i != 1 ]]; do
  4357.             i=$((i-1))
  4358.             prev=${COMP_WORDS[i-1]}
  4359.         done
  4360.     fi
  4361.  
  4362.     case "$prev" in
  4363.     -@(c|i|A|I|f|e|x|X|-@(install|unpack|record-avail|contents|info|fsys-tarfile|field|control|extract)))
  4364.         _filedir '?(u)deb'
  4365.         return 0
  4366.         ;;
  4367.     -@(b|-build))
  4368.         _filedir -d
  4369.         return 0
  4370.         ;;
  4371.        -@(s|p|l|-@(status|print-avail|list)))
  4372.         COMPREPLY=( $( apt-cache pkgnames $cur 2>/dev/null ) )
  4373.         return 0
  4374.         ;;
  4375.     -@(S|-search))
  4376.         _filedir
  4377.         return 0
  4378.         ;;
  4379.     -@(r|L|P|-@(remove|purge|listfiles)))
  4380.         COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
  4381.         return 0
  4382.         ;;
  4383.     *)
  4384.  
  4385.     COMPREPLY=( $( compgen -W '-i --install --unpack -A --record-avail \
  4386.             --configure -r --remove -P --purge --get-selections \
  4387.             --set-selections --update-avail --merge-avail \
  4388.             --clear-avail  --command-fd --forget-old-unavail -s \
  4389.             --status -p --print-avail -L --listfiles -l --list \
  4390.             -S --search -C --audit --print-architecture \
  4391.             --print-gnu-build-architecture \
  4392.             --print-installation-architecture \
  4393.             --compare-versions --help --version --force-help \
  4394.             --force-all --force-auto-select --force-downgrade \
  4395.             --force-configure-any --force-hold --force-bad-path \
  4396.             --force-not-root --force-overwrite \
  4397.             --force-overwrite-diverted --force-bad-verify \
  4398.             --force-depends-version --force-depends \
  4399.             --force-confnew --force-confold --force-confdef \
  4400.             --force-confmiss --force-conflicts --force-architecture\
  4401.             --force-overwrite-dir --force-remove-reinstreq \
  4402.             --force-remove-essential -Dh \
  4403.             --debug=help --licence --admindir= --root= --instdir= \
  4404.             -O --selected-only -E --skip-same-version \
  4405.             -G --refuse-downgrade -B --auto-deconfigure \
  4406.             --no-debsig --no-act -D --debug= --status-fd \
  4407.             -b --build -I --info -f --field -c --contents \
  4408.             -x --extract -X --vextract --fsys-tarfile -e --control \
  4409.             --ignore-depends= --abort-after' -- $cur ) )
  4410.         ;;
  4411.     esac
  4412.  
  4413.  
  4414. }
  4415. complete -F _dpkg $filenames dpkg dpkg-deb
  4416. }
  4417.  
  4418. # Debian GNU dpkg-reconfigure(8) completion
  4419. #
  4420. have dpkg-reconfigure &&
  4421. _dpkg_reconfigure()
  4422. {
  4423.     local cur prev opt
  4424.  
  4425.     COMPREPLY=()
  4426.     cur=`_get_cword`
  4427.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4428.  
  4429.  
  4430.     case "$prev" in
  4431.         -@(f|-frontend))
  4432.         opt=( $( echo /usr/share/perl5/Debconf/FrontEnd/* ) )
  4433.         opt=( ${opt[@]##*/} )
  4434.         opt=( ${opt[@]%.pm} )
  4435.         COMPREPLY=( $( compgen -W '${opt[@]}' -- $cur ) )
  4436.         return 0
  4437.         ;;
  4438.         -@(p|-priority))
  4439.           COMPREPLY=( $( compgen -W 'low medium high critical' -- $cur ) )
  4440.         return 0
  4441.         ;;
  4442.     esac
  4443.  
  4444.     if [[ "$cur" == -* ]]; then
  4445.         COMPREPLY=( $( compgen -W '-f --frontend -p --priority -a --all \
  4446.                        -u --unseen-only -h --help -s --showold \
  4447.                        --force --terse' -- $cur ) )
  4448.     else
  4449.         COMPREPLY=( $( _comp_dpkg_installed_packages $cur ) )
  4450.     fi
  4451. } &&
  4452. complete -F _dpkg_reconfigure $default dpkg-reconfigure
  4453.  
  4454. # Debian dpkg-source completion
  4455. #
  4456. have dpkg-source &&
  4457. _dpkg_source()
  4458. {
  4459.     local cur prev options work i action packopts unpackopts
  4460.  
  4461.     packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sp -su -sr -ss -sn -sA -sK -sP -sU -sR"
  4462.     unpackopts="-sp -sn -su"
  4463.     options=`echo "-x -b $packopts $unpackopts" | xargs echo | sort -u | xargs echo`
  4464.  
  4465.     COMPREPLY=()
  4466.     if [ "$1" != "dpkg-source" ]; then
  4467.         exit 1
  4468.     fi
  4469.     cur=`_get_cword`
  4470.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4471.     action="options"
  4472.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  4473.         if [[ ${COMP_WORDS[$i]} == "-x" ]]; then
  4474.             action=unpack
  4475.         elif [[ ${COMP_WORDS[$i]} == "-b" ]]; then
  4476.             action=pack
  4477.         elif [[ ${COMP_WORDS[$i]} == "-h" ]]; then
  4478.             action=help
  4479.         fi
  4480.     done
  4481.     # if currently seeing a complete option, return just itself.
  4482.     for i in $options; do
  4483.         if [ "$cur" = "$i" ]; then
  4484.             COMPREPLY=( "$cur" )
  4485.             return 0
  4486.         fi
  4487.     done
  4488.     case "$action" in
  4489.         "unpack")
  4490.             if [ "$cur" = "-" -o "$cur" = "-s" ]; then
  4491.                 COMPREPLY=( $unpackopts )
  4492.                 return 0
  4493.             fi
  4494.             case "$prev" in
  4495.                 "-x")
  4496.                     COMPREPLY=( $( compgen -d -- "$cur" ) \
  4497.                             $( compgen -f -X '!*.dsc' -- "$cur" ) )
  4498.                     return 0
  4499.                     ;;
  4500.                 *)
  4501.                     COMPREPLY=( $unpackopts $(compgen -d -f -- "$cur" ) )
  4502.                     return 0
  4503.                     ;;
  4504.             esac
  4505.             return 0
  4506.             ;;
  4507.         "pack")
  4508.             if [ "$cur" = "-" ]; then
  4509.                 COMPREPLY=( $packopts )
  4510.                 return 0
  4511.             fi
  4512.             if [ "$cur" = "-s" ]; then
  4513.                 COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \
  4514.                         "-sA" "-sK" "-sP" "-sU" "-sR" )
  4515.                 return 0
  4516.             fi
  4517.             case "$prev" in
  4518.                 "-b")
  4519.                     COMPREPLY=( $( compgen -d -- "$cur" ) )
  4520.                     return 0
  4521.                     ;;
  4522.                 "-c"|"-l"|"-T"|"-i"|"-I")
  4523.                     # -c: get controlfile
  4524.                     # -l: get per-version info from this file
  4525.                     # -T: read variables here, not debian/substvars
  4526.                     # -i: <regexp> filter out files to ignore diffs of.
  4527.                     # -I: filter out files when building tarballs.
  4528.                     # return directory names and file names
  4529.                     COMPREPLY=( $( compgen -d -f ) )
  4530.                     return 0
  4531.                     ;;
  4532.                 "-F")
  4533.                     # -F: force change log format
  4534.                     COMPREPLY=( $( ( cd /usr/lib/dpkg/parsechangelog; compgen -f "$cur" ) ) )
  4535.                     return 0
  4536.                     ;;
  4537.                 "-V"|"-D")
  4538.                     # -V: set a substitution variable
  4539.                     # we don't know anything about possible variables or values
  4540.                     # so we don't try to suggest any completion.
  4541.                     COMPREPLY=()
  4542.                     return 0
  4543.                     ;;
  4544.                 "-D")
  4545.                     # -D: override or add a .dsc field and value
  4546.                     # if $cur doesn't contain a = yet, suggest variable names
  4547.                     if echo -- "$cur" | grep -q "="; then
  4548.                         # $cur contains a "="
  4549.                         COMPREPLY=()
  4550.                         return 0
  4551.                     else
  4552.                         COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files )
  4553.                         return 0
  4554.                     fi
  4555.                     ;;
  4556.                 "-U")
  4557.                     # -U: remove a field
  4558.                     # Suggest possible fieldnames
  4559.                     COMPREPLY=( Format Source Version Binary Maintainer Uploader Architecture Standards-Version Build-Depends Files )
  4560.                     return 0
  4561.                     ;;
  4562.                 *)
  4563.                     COMPREPLY=( $packopts )
  4564.                     return 0
  4565.                     ;;
  4566.             esac
  4567.             return 0
  4568.             ;;
  4569.         *)
  4570.             # if seeing a partial option, return possible completions.
  4571.             if [ "$cur" = "-s" ]; then
  4572.                 COMPREPLY=( "-sa" "-sk" "-sp" "-su" "-sr" "-ss" "-sn" \
  4573.                         "-sA" "-sK" "-sP" "-sU" "-sR" )
  4574.                 return 0
  4575.             fi
  4576.             # else return all possible options.
  4577.             COMPREPLY=( $options )
  4578.             return 0
  4579.             ;;
  4580.     esac
  4581. } &&
  4582. complete -F _dpkg_source dpkg-source
  4583.  
  4584. # Debian Linux dselect(8) completion.
  4585. #
  4586. have dselect &&
  4587. _dselect()
  4588. {
  4589.     local cur prev
  4590.  
  4591.     COMPREPLY=()
  4592.     cur=`_get_cword`
  4593.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4594.  
  4595.     case "$prev" in
  4596.          --admindir)
  4597.           _filedir -d
  4598.           return 0
  4599.           ;;
  4600.  
  4601.          -@(D|debug))
  4602.           _filedir
  4603.           return 0
  4604.           ;;
  4605.     esac
  4606.  
  4607.     if [[ "$cur" == -* ]]; then
  4608.         COMPREPLY=( $( compgen -W '--admindir --help --version --licence \
  4609.                   --license --expert --debug' -- $cur ) )
  4610.     else
  4611.         COMPREPLY=( $( compgen -W 'access update select install config \
  4612.                   remove quit' -- $cur ) )
  4613.     fi
  4614.  
  4615.  
  4616.     return 0
  4617. } &&
  4618. complete -F _dselect $filenames dselect
  4619.  
  4620. # Java completion
  4621. #
  4622.  
  4623. # available path elements completion
  4624. have java && {
  4625. _java_path()
  4626. {
  4627.     cur=${cur##*:}
  4628.     _filedir '@(jar|zip)'
  4629. }
  4630.  
  4631. # exact classpath determination
  4632. _java_find_classpath()
  4633. {
  4634.     local i
  4635.  
  4636.     # search first in current options
  4637.     for (( i=1; i < COMP_CWORD; i++ )); do
  4638.         if [[ "${COMP_WORDS[i]}" == -@(cp|classpath) ]]; then
  4639.             classpath=${COMP_WORDS[i+1]}
  4640.             break
  4641.         fi
  4642.     done
  4643.  
  4644.     # default to environment
  4645.     [ -z "$classpath" ] && classpath=$CLASSPATH
  4646.  
  4647.     # default to current directory
  4648.     [ -z "$classpath" ] && classpath=.
  4649. }
  4650.  
  4651. # exact sourcepath determination
  4652. _java_find_sourcepath()
  4653. {
  4654.     local i
  4655.  
  4656.     # search first in current options
  4657.     for (( i=1; i < COMP_CWORD; i++ )); do
  4658.         if [[ "${COMP_WORDS[i]}" == -sourcepath ]]; then
  4659.             sourcepath=${COMP_WORDS[i+1]}
  4660.             break
  4661.         fi
  4662.     done
  4663.  
  4664.     # default to classpath
  4665.     [ -z "$sourcepath" ] && _java_find_classpath
  4666.     sourcepath=$classpath
  4667. }
  4668.  
  4669. # available classes completion
  4670. _java_classes()
  4671. {
  4672.     local classpath i
  4673.  
  4674.     # find which classpath to use
  4675.     _java_find_classpath
  4676.  
  4677.     # convert package syntax to path syntax
  4678.     cur=${cur//.//}
  4679.     # parse each classpath element for classes
  4680.     for i in ${classpath//:/ }; do
  4681.         if [ -r $i ] && [[ "$i" == *.@(jar|zip) ]]; then
  4682.             if type zipinfo &> /dev/null; then
  4683.                 COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \
  4684.                 "$i" | grep "^$cur" | grep '\.class$' | \
  4685.                 grep -v "\\$" ) )
  4686.             else
  4687.                 COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \
  4688.                 "$cur" | grep "\.class$" | grep -v "\\$" ) )
  4689.             fi
  4690.  
  4691.         elif [ -d $i ]; then
  4692.             i=${i%/}
  4693.             COMPREPLY=( "${COMPREPLY[@]}" $( find "$i" -type f \
  4694.             -path "$i/$cur*.class" 2>/dev/null | \
  4695.             grep -v "\\$" | sed -e "s|^$i/||" ) )
  4696.         fi
  4697.     done
  4698.  
  4699.     # remove class extension
  4700.     COMPREPLY=( ${COMPREPLY[@]%.class} )
  4701.     # convert path syntax to package syntax
  4702.     COMPREPLY=( ${COMPREPLY[@]//\//.} )
  4703. }
  4704.  
  4705. # available packages completion
  4706. _java_packages()
  4707. {
  4708.     local sourcepath i
  4709.  
  4710.     # find which sourcepath to use
  4711.     _java_find_sourcepath
  4712.  
  4713.     # convert package syntax to path syntax
  4714.     cur=${cur//.//}
  4715.     # parse each sourcepath element for packages
  4716.     for i in ${sourcepath//:/ }; do
  4717.         if [ -d $i ]; then
  4718.             COMPREPLY=( "${COMPREPLY[@]}" $( command ls -F -d \
  4719.                 $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) )
  4720.         fi
  4721.     done
  4722.     # keep only packages
  4723.     COMPREPLY=( $( echo "${COMPREPLY[@]}" | tr " " "\n" | grep "/$" ) )
  4724.     # remove packages extension
  4725.     COMPREPLY=( ${COMPREPLY[@]%/} )
  4726.     # convert path syntax to package syntax
  4727.     cur=${COMPREPLY[@]//\//.}
  4728. }
  4729.  
  4730. # java completion
  4731. #
  4732. _java()
  4733. {
  4734.     local cur prev i
  4735.  
  4736.     COMPREPLY=()
  4737.     cur=`_get_cword`
  4738.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4739.  
  4740.     for ((i=1; i < $COMP_CWORD; i++)); do
  4741.         case ${COMP_WORDS[$i]} in
  4742.             -cp|-classpath)
  4743.             ((i++))    # skip the classpath string.
  4744.             ;;
  4745.             -*)
  4746.             # this is an option, not a class/jarfile name.
  4747.             ;;
  4748.             *)
  4749.             # once we've seen a class, just do filename completion
  4750.             _filedir
  4751.             return 0
  4752.             ;;
  4753.         esac
  4754.     done
  4755.  
  4756.     case $prev in
  4757.         -@(cp|classpath))
  4758.             _java_path
  4759.             return 0
  4760.             ;;
  4761.     esac
  4762.  
  4763.     if [[ "$cur" == -* ]]; then
  4764.         # relevant options completion
  4765.         COMPREPLY=( $( compgen -W '-client -hotspot -server -classic \
  4766.                 -cp -classpath -D -verbose -verbose:class \
  4767.                 -verbose:gc -version:jni -version \
  4768.                 -showversion -? -help -X -jar \
  4769.                 -ea -enableassertions -da -disableassertions \
  4770.                 -esa -enablesystemassertions \
  4771.                 -dsa -disablesystemassertions ' -- $cur ) )
  4772.     else
  4773.         if [[ "$prev" == -jar ]]; then
  4774.             # jar file completion
  4775.             _filedir jar
  4776.         else
  4777.             # classes completion
  4778.             _java_classes
  4779.         fi
  4780.     fi
  4781. }
  4782. complete -F _java $filenames java
  4783. }
  4784.  
  4785. # javadoc completion
  4786. #
  4787. have javadoc &&
  4788. _javadoc()
  4789. {
  4790.     COMPREPLY=()
  4791.     local cur prev
  4792.  
  4793.     cur=`_get_cword`
  4794.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4795.  
  4796.     case $prev in
  4797.         -@(overview|helpfile|stylesheetfile))
  4798.             _filedir
  4799.             return 0
  4800.             ;;
  4801.         -d)
  4802.             _filedir -d
  4803.             return 0
  4804.             ;;
  4805.         -@(classpath|bootclasspath|docletpath|sourcepath|extdirs))
  4806.             _java_path
  4807.             return 0
  4808.             ;;
  4809.     esac
  4810.  
  4811.     if [[ "$cur" == -* ]]; then
  4812.         # relevant options completion
  4813.         COMPREPLY=( $( compgen -W '-overview -public -protected \
  4814.                 -package -private -help -doclet -docletpath \
  4815.                 -sourcepath -classpath -exclude -subpackages \
  4816.                 -breakiterator -bootclasspath -source -extdirs \
  4817.                 -verbose -locale -encoding -J -d -use -version \
  4818.                 -author -docfilessubdirs -splitindex \
  4819.                 -windowtitle -doctitle -header -footer -bottom \
  4820.                 -link -linkoffline -excludedocfilessubdir \
  4821.                 -group -nocomment -nodeprecated -noqualifier \
  4822.                 -nosince -nodeprecatedlist -notree -noindex \
  4823.                 -nohelp -nonavbar -quiet -serialwarn -tag \
  4824.                 -taglet -tagletpath -charset -helpfile \
  4825.                 -linksource -stylesheetfile -docencoding' -- \
  4826.                 $cur ) )
  4827.     else
  4828.         # source files completion
  4829.         _filedir java
  4830.         # packages completion
  4831.         _java_packages
  4832.     fi
  4833. } &&
  4834. complete -F _javadoc $filenames javadoc
  4835.  
  4836. # javac completion
  4837. #
  4838. have javac &&
  4839. _javac()
  4840. {
  4841.     COMPREPLY=()
  4842.     local cur prev
  4843.  
  4844.     cur=`_get_cword`
  4845.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4846.  
  4847.     case $prev in
  4848.         -d)
  4849.             _filedir -d
  4850.             return 0
  4851.             ;;
  4852.         -@(classpath|bootclasspath|sourcepath|extdirs))
  4853.             _java_path
  4854.             return 0
  4855.             ;;
  4856.     esac
  4857.  
  4858.     if [[ "$cur" == -* ]]; then
  4859.         # relevant options completion
  4860.         COMPREPLY=( $( compgen -W '-g -g:none -g:lines -g:vars\
  4861.         -g:source -O -nowarn -verbose -deprecation -classpath\
  4862.         -sourcepath -bootclasspath -extdirs -d -encoding -source\
  4863.         -target -help' -- $cur ) )
  4864.     else
  4865.         # source files completion
  4866.         _filedir java
  4867.     fi
  4868. } &&
  4869. complete -F _javac $filenames javac
  4870.  
  4871. # PINE address-book completion
  4872. #
  4873. have pine &&
  4874. _pineaddr()
  4875. {
  4876.     local cur
  4877.  
  4878.     COMPREPLY=()
  4879.     cur=`_get_cword`
  4880.  
  4881.     COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook 2>/dev/null)' \
  4882.             -- $cur ) )
  4883. } &&
  4884. complete -F _pineaddr $default pine
  4885.  
  4886. # mutt completion
  4887. #
  4888. # Mutt doesn't have an "addressbook" like Pine, but it has aliases and
  4889. # a "query" function to retrieve addresses, so that's what we use here.
  4890. have mutt || have muttng && {
  4891. _muttaddr()
  4892. {
  4893.     _muttaliases
  4894.     _muttquery
  4895.  
  4896.     cur=`_get_cword`
  4897.     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -u -- $cur ) )
  4898.  
  4899.     return 0
  4900. }
  4901.  
  4902. _muttconffiles()
  4903. {
  4904.     local file sofar
  4905.     local -a newconffiles
  4906.  
  4907.     sofar=" $1 "
  4908.     shift
  4909.     while [[ "$1" ]]; do
  4910.         newconffiles=( $(sed -rn 's|^source[[:space:]]+([^[:space:]]+).*$|\1|p' $(eval echo $1) ) )
  4911.         for file in "${newconffiles[@]}"; do
  4912.         [[ ! "$file" ]] || [[ "${sofar/ ${file} / }" != "$sofar" ]] &&
  4913.             continue
  4914.         sofar="$sofar $file"
  4915.         sofar=" $(eval _muttconffiles \"$sofar\" $file) "
  4916.         done
  4917.         shift
  4918.     done
  4919.     echo $sofar
  4920. }
  4921.  
  4922. _muttaliases()
  4923. {
  4924.     local cur muttrc
  4925.     local -a conffiles aliases
  4926.     cur=`_get_cword =`
  4927.  
  4928.     [ -f ~/.${muttcmd}/${muttcmd}rc ] && muttrc="~/.${muttcmd}/${muttcmd}rc"
  4929.     [ -f ~/.${muttcmd}rc ] && muttrc="~/.${muttcmd}rc"
  4930.     [ -z "$muttrc" ] && return 0
  4931.  
  4932.     conffiles=( $(eval _muttconffiles $muttrc $muttrc) )
  4933.     aliases=( $( sed -rn 's|^alias[[:space:]]+([^[:space:]]+).*$|\1|p' \
  4934.             $(eval echo "${conffiles[@]}") ) )
  4935.     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${aliases[*]}" -- $cur ) )
  4936.  
  4937.     return 0
  4938. }
  4939.  
  4940. _muttquery()
  4941. {
  4942.     local cur querycmd
  4943.     local -a queryresults
  4944.     cur=`_get_cword`
  4945.  
  4946.     querycmd="$( $muttcmd -Q query_command  | sed -r 's|^query_command=\"(.*)\"$|\1|; s|%s|'$cur'|' )"
  4947.     if [ -z "$cur" -o -z "$querycmd" ]; then
  4948.         queryresults=()
  4949.     else
  4950.         queryresults=( $( $querycmd | \
  4951.           sed -nr '2,$s|^([^[:space:]]+).*|\1|p' ) )
  4952.     fi
  4953.  
  4954.     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${queryresults[*]}" \
  4955.             -- $cur ) )
  4956.  
  4957.     return 0
  4958. }
  4959.  
  4960. _muttfiledir()
  4961. {
  4962.     local cur folder spoolfile
  4963.     cur=`_get_cword`
  4964.  
  4965.     # This is currently not working so well. Perhaps this function should
  4966.     # just call _filedir() for the moment.
  4967.     if [[ $cur == [=+]* ]]; then
  4968.         folder="$( $muttcmd -Q folder | sed -r 's|^folder=\"(.*)\"$|\1|' )"
  4969.         : folder:=~/Mail
  4970.  
  4971.         # Match any file in $folder beginning with $cur
  4972.         # (minus the leading '=' sign).
  4973.         COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
  4974.         COMPREPLY=( ${COMPREPLY[@]#$folder/} )
  4975.         return 0
  4976.     elif [ "$cur" == !* ]; then
  4977.         spoolfile="$( $muttcmd -Q spoolfile | sed -r 's|^spoolfile=\"(.*)\"$|\1|' )"
  4978.         [ ! -z "$spoolfile" ] && eval cur="${cur/^!/$spoolfile}";
  4979.     fi
  4980.     _filedir
  4981.  
  4982.     return 0
  4983. }
  4984.  
  4985. _mutt()
  4986. {
  4987.     local cur prev
  4988.     cur=`_get_cword`
  4989.     prev=${COMP_WORDS[COMP_CWORD-1]}
  4990.  
  4991.     COMPREPLY=()
  4992.  
  4993.     [ ${COMP_WORDS[0]} == muttng ] && muttcmd="muttng" || muttcmd="mutt"
  4994.  
  4995.     case "$cur" in
  4996.     -*)
  4997.         COMPREPLY=( $( compgen -W '-A -a -b -c -e -f -F -H -i -m -n \
  4998.                         -p -Q -R -s -v -x -y -z -Z -h' \
  4999.                         -- $cur ) )
  5000.         return 0
  5001.         ;;
  5002.     *)
  5003.         case "$prev" in
  5004.         -@(a|f|F|H|i))
  5005.             _muttfiledir
  5006.             return 0
  5007.             ;;
  5008.         -A)
  5009.             _muttaliases
  5010.             return 0
  5011.             ;;
  5012.         -@(e|m|Q|s|h|p|R|v|y|z|Z))
  5013.             return 0
  5014.             ;;
  5015.         *)
  5016.             _muttaddr
  5017.             return 0
  5018.             ;;
  5019.         esac
  5020.         ;;
  5021.     esac
  5022.  
  5023. }
  5024. complete -F _mutt $default $filenames mutt muttng
  5025. }
  5026.  
  5027. _configure_func()
  5028. {
  5029.     local cur
  5030.  
  5031.     COMPREPLY=()
  5032.     cur=`_get_cword`
  5033.  
  5034.     # if $COMP_CONFIGURE_HINTS is not null, then completions of the form
  5035.     # --option=SETTING will include 'SETTING' as a contextual hint
  5036.     [[ "$cur" != -* ]] && return 0
  5037.  
  5038.     if [ -n "$COMP_CONFIGURE_HINTS" ]; then
  5039.         COMPREPLY=( $( $1 --help | awk '/^  --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' | grep ^$cur ) )
  5040.  
  5041.     else
  5042.         COMPREPLY=( $( $1 --help | awk '/^  --[A-Za-z]/ { print $1; if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,=].*//g' | grep ^$cur ) )
  5043.     fi
  5044. }
  5045. complete -F _configure_func $default configure
  5046.  
  5047. # Debian reportbug(1) completion
  5048. #
  5049. have reportbug &&
  5050. _reportbug()
  5051. {
  5052.     local cur prev
  5053.  
  5054.     COMPREPLY=()
  5055.     cur=`_get_cword`
  5056.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5057.  
  5058.     case "$prev" in
  5059.         -f|--filename|-i|--include|--mta|-o|--output)
  5060.         _filedir
  5061.         return 0
  5062.         ;;
  5063.         -B|--bts)
  5064.         COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \
  5065.                    $cur ))
  5066.         return 0
  5067.         ;;
  5068.         -e|--editor|--mua)
  5069.         COMP_WORDS=(COMP_WORDS[0] $cur)
  5070.         COMP_CWORD=1
  5071.         _command
  5072.         return 0
  5073.         ;;
  5074.         --mode)
  5075.         COMPREPLY=( $( compgen -W "novice standard expert" -- $cur ) )
  5076.         return 0
  5077.         ;;
  5078.         -S|--severity)
  5079.         COMPREPLY=( $( compgen -W "grave serious important normal \
  5080.                        minor wishlist" -- $cur ) )
  5081.         return 0
  5082.         ;;
  5083.         -u|--ui|--interface)
  5084.         COMPREPLY=( $( compgen -W "newt text gnome" -- $cur ) )
  5085.         return 0
  5086.         ;;
  5087.         -t|--type)
  5088.         COMPREPLY=( $( compgen -W "gnats debbugs" -- $cur ) )
  5089.         return 0
  5090.         ;;
  5091.         -T|--tags)
  5092.         COMPREPLY=( $( compgen -W "none \
  5093.                        woody potato sarge sarge-ignore etch etch-ignore \
  5094.                        lenny lenny-ignore sid experimental confirmed \
  5095.                        d-i fixed fixed-in-experimental fixed-upstream \
  5096.                        help l10n moreinfo patch pending security \
  5097.                        unreproducible upstream wontfix ipv6 lfs" -- $cur ))
  5098.         return 0
  5099.         ;;
  5100.         *)
  5101.         ;;
  5102.     esac
  5103.  
  5104.     COMPREPLY=($( compgen -W '-h --help -v --version -a --af -b \
  5105.             --no-query-bts --query-bts -B --bts -c --configure \
  5106.             --no-config-files --check-available -d --debug \
  5107.             --no-check-available -e --editor --email -f \
  5108.             --filename -g --gnupg -H --header -i --include -j \
  5109.             --justification -l --ldap --no-ldap -L --list-cc -m \
  5110.             --maintonly --mode --mua --mta --mutt -n --mh --nmh \
  5111.             -o --output -p --print -P --pgp --proxy --http_proxy\
  5112.             -q --quiet -Q --query-only --realname --report-quiet \
  5113.             --reply-to --replyto -s --subject -S --severity \
  5114.             --smtphost -t --type -T --tags --template -V -x \
  5115.             --no-cc --package-version -z --no-compress \
  5116.             --ui --interface -u \
  5117.             wnpp boot-floppies kernel bugs.debian.org \
  5118.             cdimage.debian.org general installation-reports \
  5119.             listarchives lists.debian.org mirrors nm.debian.org \
  5120.             press project qa.debian.org release-notes \
  5121.             security.debian.org tech-ctte upgrade-reports \
  5122.             www.debian.org' -- $cur ) \
  5123.                 $( apt-cache pkgnames -- $cur 2> /dev/null) )
  5124.     _filedir
  5125.     return 0
  5126. } &&
  5127. complete -F _reportbug $filenames reportbug
  5128.  
  5129. # Debian querybts(1) completion
  5130. #
  5131. have querybts &&
  5132. _querybts()
  5133. {
  5134.     local cur prev
  5135.  
  5136.     COMPREPLY=()
  5137.     cur=`_get_cword`
  5138.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5139.  
  5140.     case "$prev" in
  5141.         -B|--bts)
  5142.         COMPREPLY=( $( compgen -W "debian guug kde mandrake help" -- \
  5143.                    $cur ))
  5144.         return 0
  5145.         ;;
  5146.         -u|--ui|--interface)
  5147.         COMPREPLY=($( compgen -W "newt text gnome" -- $cur ))
  5148.         return 0
  5149.         ;;
  5150.         *)
  5151.         ;;
  5152.     esac
  5153.  
  5154.     COMPREPLY=($( compgen -W '-h --help -v --version -A --archive \
  5155.             -B --bts -l --ldap --no-ldap --proxy= --http_proxy= \
  5156.             -s --source -w --web -u --ui --interface \
  5157.             wnpp boot-floppies kernel bugs.debian.org \
  5158.             cdimage.debian.org general installation-reports \
  5159.             listarchives lists.debian.org mirrors nm.debian.org \
  5160.             press project qa.debian.org release-notes \
  5161.             security.debian.org tech-ctte upgrade-reports \
  5162.             www.debian.org' -- $cur ) \
  5163.                 $( apt-cache pkgnames -- $cur 2> /dev/null) )
  5164. } &&
  5165. complete -F _querybts $filenames querybts
  5166.  
  5167. # update-alternatives completion
  5168. #
  5169. have update-alternatives && {
  5170. installed_alternatives()
  5171. {
  5172.     local admindir
  5173.     # find the admin dir
  5174.     for i in alternatives dpkg/alternatives rpm/alternatives; do
  5175.         [ -d /var/lib/$i ] && admindir=/var/lib/$i && break
  5176.     done
  5177.     for (( i=1; i < COMP_CWORD; i++ )); do
  5178.         if [[ "${COMP_WORDS[i]}" == --admindir ]]; then
  5179.             admindir=${COMP_WORDS[i+1]}
  5180.             break
  5181.         fi
  5182.     done
  5183.     COMPREPLY=( $( command ls $admindir | grep "^$cur" ) )
  5184. }
  5185.  
  5186. _update_alternatives()
  5187. {
  5188.     local cur prev mode args i
  5189.  
  5190.     COMPREPLY=()
  5191.     cur=`_get_cword`
  5192.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5193.  
  5194.     case "$prev" in
  5195.     --@(altdir|admindir))
  5196.         _filedir -d
  5197.         return 0
  5198.         ;;
  5199.     --@(help|version))
  5200.         return 0
  5201.         ;;
  5202.     esac
  5203.  
  5204.     # find which mode to use and how many real args used so far
  5205.     for (( i=1; i < COMP_CWORD; i++ )); do
  5206.         if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all) ]]; then
  5207.             mode=${COMP_WORDS[i]}
  5208.             args=$(($COMP_CWORD - i))
  5209.             break
  5210.         fi
  5211.     done
  5212.  
  5213.     case $mode in
  5214.     --install)
  5215.         case $args in
  5216.         1)
  5217.             _filedir
  5218.             ;;
  5219.         2)
  5220.             installed_alternatives
  5221.             ;;
  5222.         3)
  5223.             _filedir
  5224.             ;;
  5225.         esac
  5226.         ;;
  5227.     --remove)
  5228.         case $args in
  5229.         1)
  5230.             installed_alternatives
  5231.             ;;
  5232.         2)
  5233.             _filedir
  5234.             ;;
  5235.         esac
  5236.         ;;
  5237.     --auto)
  5238.         installed_alternatives
  5239.         ;;
  5240.     --remove-all)
  5241.         installed_alternatives
  5242.         ;;
  5243.     --display)
  5244.         installed_alternatives
  5245.         ;;
  5246.     --config)
  5247.         installed_alternatives
  5248.         ;;
  5249.     *)
  5250.         COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \
  5251.                    --altdir --admindir' -- $cur ) \
  5252.                 $( compgen -W '--install --remove --auto --display \
  5253.                    --config' -- $cur ) )
  5254.     esac
  5255. }
  5256. complete -F _update_alternatives update-alternatives
  5257. }
  5258.  
  5259. # Python completion
  5260. #
  5261. have python &&
  5262. _python()
  5263. {
  5264.     local prev cur
  5265.  
  5266.     COMPREPLY=()
  5267.     cur=`_get_cword`
  5268.     prev=${COMP_WORDS[COMP_CWORD-1]##*/}
  5269.  
  5270.     case "$prev" in
  5271.     -Q)
  5272.         COMPREPLY=( $( compgen -W "old new warn warnall" -- $cur ) )
  5273.         return 0
  5274.         ;;
  5275.     -W)
  5276.         COMPREPLY=( $( compgen -W "ignore default all module once error" -- $cur ) )
  5277.         return 0
  5278.         ;;
  5279.     -c)
  5280.         _filedir '@(py|pyc|pyo)'
  5281.         return 0
  5282.         ;;
  5283.     !(python|-?))
  5284.         [[ ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] && _filedir
  5285.         ;;
  5286.     esac
  5287.  
  5288.  
  5289.     # if '-c' is already given, complete all kind of files.
  5290.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  5291.         if [[ ${COMP_WORDS[i]} == -c ]]; then
  5292.             _filedir
  5293.         fi
  5294.     done
  5295.  
  5296.  
  5297.     if [[ "$cur" != -* ]]; then
  5298.         _filedir '@(py|pyc|pyo)'
  5299.     else
  5300.         COMPREPLY=( $( compgen -W "- -d -E -h -i -O -Q -S -t -u \
  5301.                        -U -v -V -W -x -c" -- $cur ) )
  5302.     fi
  5303.  
  5304.  
  5305.  
  5306.     return 0
  5307. } &&
  5308. complete -F _python $filenames python
  5309.  
  5310. # Perl completion
  5311. #
  5312. have perl &&
  5313. {
  5314. _perlmodules()
  5315. {
  5316.     COMPREPLY=( $( compgen -P "$prefix" -W "$( perl -e 'sub mods { my ($base,$dir)=@_; return if  $base !~ /^\Q$ENV{cur}/; chdir($dir) or return; for (glob(q[*.pm])) {s/\.pm$//; print qq[$base$_\n]}; mods(/^(?:[.\d]+|$Config{archname}-$Config{osname}|auto)$/ ? undef : qq[${base}${_}\\\\:\\\\:],qq[$dir/$_]) for grep {-d} glob(q[*]); } mods(undef,$_) for @INC;' )" -- $cur ) )
  5317. }
  5318.  
  5319. _perl()
  5320. {
  5321.     local cur prev prefix temp
  5322.  
  5323.     COMPREPLY=()
  5324.     cur=`_get_cword`
  5325.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5326.     prefix=""
  5327.  
  5328.     # completing an option (may or may not be separated by a space)
  5329.     if [[ "$cur" == -?* ]]; then
  5330.     temp=$cur
  5331.     prev=${temp:0:2}
  5332.     cur=${temp:2}
  5333.     prefix=$prev
  5334.     fi
  5335.  
  5336.     # only handle module completion for now
  5337.     case "$prev" in
  5338.     -I|-x)
  5339.         COMPREPLY=( $( compgen -d -P "$prev" -- "$cur" ) )
  5340.         return 0
  5341.         ;;
  5342.     -m|-M)
  5343.         _perlmodules
  5344.         return 0
  5345.         ;;
  5346.     esac
  5347.  
  5348.     # handle case where first parameter is not a dash option
  5349.     if [[ "`_get_cword`" != -* ]]; then
  5350.     _filedir
  5351.     return 0
  5352.     fi
  5353.  
  5354.     # complete using basic options
  5355.     COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d -D -p \
  5356.             -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- $cur ) )
  5357.     return 0
  5358. }
  5359. complete -F _perl $filenames perl
  5360.  
  5361. _perldoc()
  5362. {
  5363.     local cur prev prefix temp
  5364.  
  5365.     COMPREPLY=()
  5366.     cur=`_get_cword`
  5367.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5368.     prefix=""
  5369.  
  5370.     # completing an option (may or may not be separated by a space)
  5371.     if [[ "$cur" == -?* ]]; then
  5372.     temp=$cur
  5373.     prev=${temp:0:2}
  5374.     cur=${temp:2}
  5375.     prefix=$prev
  5376.     fi
  5377.  
  5378.     # complete builtin perl functions
  5379.     case $prev in
  5380.     -f)
  5381.         COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \
  5382.         lcfirst length oct ord pack q qq reverse rindex sprintf \
  5383.         substr tr uc ucfirst y m pos quotemeta s split study qr abs \
  5384.         atan2 cos exp hex int log oct rand sin sqrt srand pop push \
  5385.         shift splice unshift grep join map qw reverse sort unpack \
  5386.         delete each exists keys values binmode close closedir \
  5387.         dbmclose dbmopen die eof fileno flock format getc print \
  5388.         printf read readdir rewinddir seek seekdir select syscall \
  5389.         sysread sysseek syswrite tell telldir truncate warn write \
  5390.         pack read syscall sysread syswrite unpack vec -X chdir chmod \
  5391.         chown chroot fcntl glob ioctl link lstat mkdir open opendir \
  5392.         readlink rename rmdir stat symlink umask unlink utime caller \
  5393.         continue do dump eval exit goto last next redo return \
  5394.         sub wantarray caller import local my our package use defined \
  5395.         formline reset scalar undef \
  5396.         alarm exec fork getpgrp getppid getpriority kill pipe qx \
  5397.         setpgrp setpriority sleep system times wait waitpid \
  5398.         import no package require use bless dbmclose dbmopen package \
  5399.         ref tie tied untie use accept bind connect getpeername \
  5400.         getsockname getsockopt listen recv send setsockopt shutdown \
  5401.         socket socketpair msgctl msgget msgrcv msgsnd semctl semget \
  5402.         semop shmctl shmget shmread shmwrite endgrent endhostent \
  5403.         endnetent endpwent getgrent getgrgid getgrnam getlogin \
  5404.         getpwent getpwnam getpwuid setgrent setpwent endprotoent \
  5405.         endservent gethostbyaddr gethostbyname gethostent \
  5406.         getnetbyaddr getnetbyname getnetent getprotobyname \
  5407.         getprotobynumber getprotoent getservbyname getservbyport \
  5408.         getservent sethostent setnetent setprotoent setservent \
  5409.         gmtime localtime time times' -- $cur ) )
  5410.         return 0
  5411.         ;;
  5412.     esac
  5413.  
  5414.     case $cur in
  5415.     -*)
  5416.         COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- $cur ))
  5417.         return 0
  5418.         ;;
  5419.     */*)
  5420.         return 0
  5421.         ;;
  5422.     *)
  5423.         _perlmodules
  5424.         COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '$( PAGER=/bin/cat man perl |  sed -ne "/perl.*Perl overview/,/perlwin32/p" | awk "\$NF=2 { print \$1}" | grep perl )' -- $cur ) )
  5425.  
  5426.         return 0
  5427.         ;;
  5428.     esac
  5429. }
  5430. complete -F _perldoc $default perldoc
  5431. }
  5432.  
  5433. # rcs(1) completion
  5434. #
  5435. have rcs &&
  5436. _rcs()
  5437. {
  5438.     local cur prev file dir i
  5439.  
  5440.     COMPREPLY=()
  5441.     cur=`_get_cword`
  5442.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5443.  
  5444.     file=${cur##*/}
  5445.     dir=${cur%/*}
  5446.  
  5447.     # deal with relative directory
  5448.     [ "$file" = "$dir" ] && dir=.
  5449.  
  5450.     COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) )
  5451.  
  5452.     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  5453.         file=${COMPREPLY[$i]##*/}
  5454.         dir=${COMPREPLY[$i]%RCS/*}
  5455.         COMPREPLY[$i]=$dir$file
  5456.     done
  5457.  
  5458.     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -G "$dir/$file*,v" ) )
  5459.  
  5460.     for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
  5461.         COMPREPLY[$i]=${COMPREPLY[$i]%,v}
  5462.     done
  5463.  
  5464.     # default to files if nothing returned and we're checking in.
  5465.     # otherwise, default to directories
  5466.     [ ${#COMPREPLY[@]} -eq 0 -a $1 = ci ] && _filedir || _filedir -d
  5467. } &&
  5468. complete -F _rcs $filenames ci co rlog rcs rcsdiff
  5469.  
  5470. # lilo(8) completion
  5471. #
  5472. have lilo && {
  5473. _lilo_labels()
  5474. {
  5475.     COMPREPLY=( $( awk -F'=' '/label/ {print $2}' \
  5476.         /etc/lilo.conf | sed -e 's/"//g' | grep "^$cur" ) )
  5477. }
  5478.  
  5479. _lilo()
  5480. {
  5481.     local cur prev
  5482.  
  5483.     COMPREPLY=()
  5484.     cur=`_get_cword`
  5485.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5486.  
  5487.     case $prev in
  5488.         -@(C|i|m|s|S))
  5489.             _filedir
  5490.             return 0
  5491.             ;;
  5492.         -r)
  5493.             _filedir -d
  5494.             return 0
  5495.             ;;
  5496.         -@(I|D|R))
  5497.             # label completion
  5498.             _lilo_labels
  5499.             return 0
  5500.             ;;
  5501.         -@(A|b|M|u|U))
  5502.             # device completion
  5503.             cur=${cur:=/dev/}
  5504.             _filedir
  5505.             return 0
  5506.             ;;
  5507.         -T)
  5508.             # topic completion
  5509.             COMPREPLY=( $( compgen -W 'help ChRul EBDA geom geom= \
  5510.                     table= video' -- $cur ) )
  5511.             return 0
  5512.             ;;
  5513.     esac
  5514.  
  5515.     if [[ "$cur" == -* ]]; then
  5516.         # relevant options completion
  5517.         COMPREPLY=( $( compgen -W '-A -b -c -C -d -f -g -i -I -l -L -m \
  5518.             -M -p -P -q -r -R -s -S -t -T -u -U -v -V -w -x -z' -- \
  5519.             $cur ) )
  5520.     fi
  5521. }
  5522. complete -F _lilo lilo
  5523. }
  5524.  
  5525. # links completion
  5526. #
  5527. have links &&
  5528. _links()
  5529. {
  5530.     local cur
  5531.  
  5532.     COMPREPLY=()
  5533.     cur=`_get_cword`
  5534.  
  5535.     case "$cur" in
  5536.         --*)
  5537.         COMPREPLY=( $( compgen -W '--help' -- $cur ) )
  5538.         ;;
  5539.         -*)
  5540.         COMPREPLY=( $( compgen -W '-async-dns -max-connections \
  5541.                 -max-connections-to-host -retries \
  5542.                 -receive-timeout -unrestartable-receive-timeout\
  5543.                 -format-cache-size -memory-cache-size \
  5544.                 -http-proxy -ftp-proxy -download-dir \
  5545.                 -assume-codepage -anonymous -dump -no-connect \
  5546.                 -source -version -help' -- $cur ) )
  5547.         ;;
  5548.         *)
  5549.         if [ -r ~/.links/links.his ]; then
  5550.             COMPREPLY=( $( compgen -W '$( < ~/.links/links.his )' \
  5551.                    -- $cur ) )
  5552.         fi
  5553.                 _filedir '@(htm|html)'
  5554.                 return 0
  5555.         ;;
  5556.     esac
  5557.  
  5558.     return 0
  5559. } &&
  5560. complete -F _links $filenames links
  5561.  
  5562. [ $UNAME = FreeBSD ] && {
  5563. # FreeBSD package management tool completion
  5564. #
  5565. _pkg_delete()
  5566. {
  5567.     local cur pkgdir prev
  5568.  
  5569.     pkgdir=${PKG_DBDIR:-/var/db/pkg}/
  5570.     cur=`_get_cword`
  5571.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5572.  
  5573.     [ "$prev" = "-o" -o "$prev" = "-p" -o "$prev" = "-W" ] && return 0
  5574.  
  5575.     COMPREPLY=( $( compgen -d $pkgdir$cur ) )
  5576.     COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
  5577.  
  5578.     return 0
  5579. }
  5580. complete -F _pkg_delete $dirnames pkg_delete pkg_info
  5581. have pkg_deinstall && complete -F _pkg_delete $dirnames pkg_deinstall
  5582.  
  5583. # FreeBSD kernel module commands
  5584. #
  5585. _kldload()
  5586. {
  5587.     local cur moddir
  5588.  
  5589.     moddir=/modules/
  5590.     [ -d $moddir ] || moddir=/boot/kernel/
  5591.     cur=`_get_cword`
  5592.  
  5593.     COMPREPLY=( $( compgen -f $moddir$cur ) )
  5594.     COMPREPLY=( ${COMPREPLY[@]#$moddir} )
  5595.     COMPREPLY=( ${COMPREPLY[@]%.ko} )
  5596.  
  5597.     return 0
  5598. }
  5599. complete -F _kldload $filenames kldload
  5600.  
  5601. _kldunload()
  5602. {
  5603.     local cur
  5604.     cur=`_get_cword`
  5605.     COMPREPLY=( $(kldstat | sed -ne "s/^.*[ \t]\+\($cur[a-z_]\+\).ko$/\1/p") )
  5606. }
  5607. complete -F _kldunload $filenames kldunload
  5608. }
  5609.  
  5610. # FreeBSD portupgrade completion
  5611. #
  5612. have portupgrade &&
  5613. _portupgrade()
  5614. {
  5615.     local cur pkgdir prev
  5616.  
  5617.     pkgdir=${PKG_DBDIR:-/var/db/pkg}/
  5618.     cur=`_get_cword`
  5619.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5620.  
  5621.     [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0
  5622.  
  5623.     COMPREPLY=( $( compgen -d $pkgdir$cur ) )
  5624.     COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
  5625.     COMPREPLY=( ${COMPREPLY[@]%-*} )
  5626.  
  5627.     return 0
  5628. } &&
  5629. complete -F _portupgrade $dirnames portupgrade
  5630.  
  5631. # FreeBSD portinstall completion
  5632. #
  5633. have portinstall &&
  5634. _portinstall()
  5635. {
  5636.     local cur portsdir prev indexfile
  5637.     local -a COMPREPLY2
  5638.  
  5639.     portsdir=${PORTSDIR:-/usr/ports}/
  5640.     cur=`_get_cword`
  5641.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5642.     # First try INDEX-5
  5643.     indexfile=$portsdir/INDEX-5
  5644.     # Then INDEX if INDEX-5 does not exist or system is not FreeBSD 5.x
  5645.     [ "${OSTYPE%.*}" = "freebsd5" -a -f $indexfile ] ||
  5646.       indexfile=$portsdir/INDEX
  5647.  
  5648.     [ "$prev" = "-l" -o "$prev" = "-L" -o "$prev" = "-o" ] && return 0
  5649.  
  5650.     COMPREPLY=( $( egrep "^$cur" < $indexfile | cut -d'|' -f1 ) )
  5651.     COMPREPLY2=( $( egrep "^[^\|]+\|$portsdir$cur" < $indexfile | \
  5652.             cut -d'|' -f2 ) )
  5653.     COMPREPLY2=( ${COMPREPLY2[@]#$portsdir} )
  5654.     COMPREPLY=( "${COMPREPLY[@]}" "${COMPREPLY2[@]}" )
  5655.  
  5656.     return 0
  5657. } &&
  5658. complete -F _portinstall $dirnames portinstall
  5659.  
  5660. # Slackware Linux removepkg completion
  5661. #
  5662. have removepkg && [ -f /etc/slackware-version ] &&
  5663. _removepkg()
  5664. {
  5665.     local packages cur
  5666.  
  5667.     COMPREPLY=()
  5668.     cur=`_get_cword`
  5669.  
  5670.     COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) )
  5671. } &&
  5672. complete -F _removepkg $filenames removepkg &&
  5673.     complete $dirnames -f -X '!*.tgz' installpkg upgradepkg explodepkg
  5674.  
  5675. # look(1) completion
  5676. #
  5677. have look &&
  5678. _look()
  5679. {
  5680.     local cur
  5681.  
  5682.     COMPREPLY=()
  5683.     cur=`_get_cword`
  5684.  
  5685.     if [ $COMP_CWORD = 1 ]; then
  5686.         COMPREPLY=( $( compgen -W '$(look $cur)' ) )
  5687.     fi
  5688. } &&
  5689. complete -F _look $default look
  5690.  
  5691. # ypcat(1) and ypmatch(1) completion
  5692. #
  5693. have ypmatch &&
  5694. _ypmatch()
  5695. {
  5696.     local cur map
  5697.  
  5698.     COMPREPLY=()
  5699.     cur=`_get_cword`
  5700.  
  5701.     [ $1 = ypcat ] && [ $COMP_CWORD -gt 1 ] && return 0
  5702.     [ $1 = ypmatch ] && [ $COMP_CWORD -gt 2 ] && return 0
  5703.  
  5704.     if [ $1 = ypmatch ] && [ $COMP_CWORD -eq 1 ] && \
  5705.        [ ${#COMP_WORDS[@]} -eq 3 ]; then
  5706.         map=${COMP_WORDS[2]}
  5707.         COMPREPLY=( $( compgen -W '$( ypcat $map | \
  5708.                         cut -d':' -f 1 )' -- $cur) )
  5709.     else
  5710.         [ $1 = ypmatch ] && [ $COMP_CWORD -ne 2 ] && return 0
  5711.         COMPREPLY=( $( compgen -W \
  5712.                   '$( echo $(ypcat -x | cut -d"\"" -f 2))' -- $cur))
  5713.     fi
  5714.  
  5715.     return 0
  5716. } &&
  5717. complete -F _ypmatch ypmatch ypcat
  5718.  
  5719. #xrandr(1) completion
  5720. #
  5721. have xrandr &&
  5722. _xrandr()
  5723. {
  5724.     local cur prev output modes
  5725.     COMPREPLY=()
  5726.     cur=`_get_cword`
  5727.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5728.  
  5729.     case "$prev" in
  5730.         --output)
  5731.             local outputs=$(xrandr|grep 'connected'|awk '{print $1}')
  5732.             COMPREPLY=( $(compgen -W "$outputs" -- $cur))
  5733.             return 0
  5734.             ;;
  5735.         --mode)
  5736.             for(( i = 1; i < COMP_CWORD; i++ )); do
  5737.                 if [[ "${COMP_WORDS[i]}" == "--output" ]]; then
  5738.                     output=${COMP_WORDS[i+1]}
  5739.                     break
  5740.                 fi
  5741.             done
  5742.             modes=$(xrandr|sed -e "1,/$output/ d" \
  5743.             -e "/connected/,$ d"|awk '{print $1}')
  5744.             COMPREPLY=( $( compgen -W "$modes" -- $cur))
  5745.             return 0
  5746.             ;;
  5747.     esac
  5748.  
  5749.     case "$cur" in
  5750.         *)
  5751.             COMPREPLY=( $(compgen -W '-d -display -help -o \
  5752.                     --orientation -q --query -s --size\
  5753.                     -r --rate -v --version -x -y --screen \
  5754.                     --verbose --dryrun --prop --fb --fbmm --dpi \
  5755.                     --output --auto --mode --preferred --pos \
  5756.                     --reflect --rotate --left-of --right-of \
  5757.                     --above --below --same-as --set --off --crtc \
  5758.                     --newmode --rmmode --addmode --delmode' -- $cur))
  5759.             return 0
  5760.             ;;
  5761.     esac
  5762.  
  5763.     return 0
  5764. } &&
  5765. complete -F _xrandr xrandr
  5766.  
  5767.  
  5768.  
  5769. # mplayer(1) completion
  5770. #
  5771. have mplayer && {
  5772. _mplayer_options_list()
  5773. {
  5774.     cur=${cur%\\}
  5775.     COMPREPLY=( $( $1 $2 help 2> /dev/null | \
  5776.         sed -e '1,/^Available/d' | awk '{print $1}' | \
  5777.         sed -e 's/:$//' -e 's/^'${2#-}'$//' -e 's/<.*//' | \
  5778.         grep "^$cur" ) )
  5779. }
  5780.  
  5781. _mplayer()
  5782. {
  5783.     local cmd cur prev skinsdir IFS=$' \t\n' i j k=0
  5784.  
  5785.     COMPREPLY=()
  5786.     cmd=${COMP_WORDS[0]}
  5787.     cur=`_get_cword`
  5788.     prev=${COMP_WORDS[COMP_CWORD-1]}
  5789.  
  5790.     case "$prev" in
  5791.         -@(ac|afm|vc|vfm|ao|vo|vop|fstype|demuxer|vf|af))
  5792.             _mplayer_options_list mplayer $prev
  5793.             return 0
  5794.             ;;
  5795.         -@(oac|ovc|of))
  5796.             _mplayer_options_list mencoder $prev
  5797.             return 0
  5798.             ;;
  5799.         -audiofile)
  5800.             _filedir '@(mp3|MP3|mpg|MPG|ogg|OGG|w?(a)v|W?(A)V|mid|MID|flac|FLAC|mka|MKA)'
  5801.             return 0
  5802.             ;;
  5803.         -font)
  5804.             _filedir '@(desc|ttf)'
  5805.             return 0
  5806.             ;;
  5807.         -sub)
  5808.             _filedir '@(srt|SRT|sub|SUB|txt|TXT|utf|UTF|rar|RAR|mpsub|smi|js|ssa|SSA|aas|AAS)'
  5809.             return 0
  5810.             ;;
  5811.         -vobsub)
  5812.             _filedir '@(idx|IDX|ifo|IFO|sub|SUB)'
  5813.             IFS=$'\t\n'
  5814.             COMPREPLY=( $( for i in "${COMPREPLY[@]}"; do
  5815.                         if [ -f $i -a -r $i ]; then
  5816.                             echo ${i%.*}
  5817.                         else
  5818.                             echo $i
  5819.                         fi
  5820.                        done ) )
  5821.             IFS=$' \t\n'
  5822.             return 0
  5823.             ;;
  5824.         -ifo)
  5825.             _filedir '@(ifo|IFO)'
  5826.             return 0
  5827.             ;;
  5828.         -cuefile)
  5829.             _filedir '@(bin|BIN|cue|CUE)'
  5830.             return 0
  5831.             ;;
  5832.         -skin)
  5833.             # if you don't have installed mplayer in /usr/local you
  5834.             # may want to set the MPLAYER_SKINS_DIR global variable
  5835.             if [ -n "$MPLAYER_SKINS_DIR" ]; then
  5836.                 skinsdir=$MPLAYER_SKINS_DIR
  5837.             else
  5838.                 skinsdir=/usr/local/share/mplayer/Skin
  5839.             fi
  5840.  
  5841.             IFS=$'\t\n'
  5842.             for i in ~/.mplayer/Skin $skinsdir; do
  5843.                 if [ -d $i -a -r $i ]; then
  5844.                     for j in $( compgen -d $i/$cur ); do
  5845.                         COMPREPLY[$k]=${j#$i/}
  5846.                         k=$((++k))
  5847.                     done
  5848.                 fi
  5849.             done
  5850.             IFS=$' \t\n'
  5851.             return 0
  5852.             ;;
  5853.         -@(mixer|@(cdrom|dvd)-device|dvdauth|fb|zrdev))
  5854.             cur=${cur:=/dev/}
  5855.             _filedir
  5856.             return 0
  5857.             ;;
  5858.         -@(edl?(out)|lircconf|menu-cfg|playlist|csslib|dumpfile)| \
  5859.         -@(subfile|vobsub|aofile|fbmodeconfig|include|o|dvdkey)| \
  5860.         -passlogfile)
  5861.             _filedir
  5862.             return 0
  5863.             ;;
  5864.         -@(auto@(q|sync)|loop|menu-root|speed|sstep|aid|alang)| \
  5865.         -@(?(@(audio|sub)-)demuxer|bandwidth|cache|chapter)| \
  5866.         -@(dvd?(angle)|fps|frames|mc|passwd|user|sb|srate|ss|vcd)| \
  5867.         -@(vi?(d|vo)|ffactor|sid|slang|spu@(align|aa|gauss))| \
  5868.         -@(vobsubid|delay|bpp|brightness|contrast|dfbopts|display)| \
  5869.         -@(fbmode|geometry|guiwid|hue|icelayer|screen[wh]|wid)| \
  5870.         -@(monitor@(aspect|-@(dotclock|[hv]freq))|panscan|saturation)| \
  5871.         -@(xineramascreen|zr@(crop|norm|quality|[xy]doff|[vh]dec))| \
  5872.         -@(aspect|pp|x|y|xy|z|stereo|audio-@(density|delay|preload))| \
  5873.         -@(endpos|osdlevel|ffourcc|sws|channels|skiplimit|format)| \
  5874.         -@(ofps|aa@(driver|@(osd|sub)color)|vobsubout?(i@(ndex|d)))| \
  5875.         -sub@(-bg-@(alpha|color)|cp|delay|fps|pos|align|width)| \
  5876.         -sub@(font-@(blur|outline|autoscale|encoding|@(osd|text)-scale)))
  5877.             return 0
  5878.             ;;
  5879.         -lavdopts)
  5880.             COMPREPLY=( $( compgen -W 'ec er= bug= idct= gray' \
  5881.                     -- $cur ) )
  5882.             return 0
  5883.             ;;
  5884.         -lavcopts)
  5885.             COMPREPLY=( $( compgen -W 'vcodec= vqmin= vqscale= \
  5886.                     vqmax= mbqmin= mbqmax= vqdiff= \
  5887.                     vmax_b_frames= vme= vhq v4mv \
  5888.                     keyint= vb_strategy= vpass= \
  5889.                     aspect= vbitrate= vratetol= \
  5890.                     vrc_maxrate= vrc_minrate= \
  5891.                     vrc_buf_size= vb_qfactor= vi_qfactor= \
  5892.                     vb_qoffset= vi_qoffset= vqblur= \
  5893.                     vqcomp= vrc_eq= vrc_override= \
  5894.                     vrc_init_cplx= vqsquish= vlelim= \
  5895.                     vcelim= vstrict= vdpart vpsize= gray \
  5896.                     vfdct= idct= lumi_mask= dark_mask= \
  5897.                     tcplx_mask= scplx_mask= naq ildct \
  5898.                     format= pred qpel precmp= cmp= \
  5899.                     subcmp= predia= dia= trell last_pred= \
  5900.                     preme= subq= psnr mpeg_quant aic umv' \
  5901.                     -- $cur ) )
  5902.             return 0
  5903.             ;;
  5904.         -ssf)
  5905.             COMPREPLY=( $( compgen -W 'lgb= cgb= ls= cs= chs= \
  5906.                     cvs=' -- $cur ) )
  5907.             return 0
  5908.             ;;
  5909.         -jpeg)
  5910.             COMPREPLY=( $( compgen -W 'noprogressive progressive \
  5911.                     nobaseline baseline optimize= \
  5912.                     smooth= quality= outdir=' -- $cur ) )
  5913.             return 0
  5914.             ;;
  5915.         -xvidopts)
  5916.             COMPREPLY=( $( compgen -W 'dr2 nodr2' -- $cur ) )
  5917.             return 0
  5918.             ;;
  5919.         -xvidencopts)
  5920.             COMPREPLY=( $( compgen -W 'pass= bitrate= \
  5921.                     fixed_quant= me_quality= 4mv \
  5922.                     rc_reaction_delay_factor= \
  5923.                     rc_averaging_period= rc_buffer= \
  5924.                     quant_range= min_key_interval= \
  5925.                     max_key_interval= mpeg_quant \
  5926.                     mod_quant lumi_mask hintedme \
  5927.                     hintfile debug keyframe_boost= \
  5928.                     kfthreshold= kfreduction=' -- $cur ) )
  5929.             return 0
  5930.             ;;
  5931.         -divx4opts)
  5932.             COMPREPLY=( $( compgen -W 'br= key= deinterlace q= \
  5933.                     min_quant= max_quant= rc_period= \
  5934.                     rc_reaction_period= crispness= \
  5935.                     rc_reaction_ratio= pass= vbrpass= \
  5936.                     help' -- $cur ) )
  5937.             return 0
  5938.             ;;
  5939.         -info)
  5940.             COMPREPLY=( $( compgen -W 'name= artist= genre= \
  5941.                     subject= copyright= srcform= \
  5942.                     comment= help' -- $cur ) )
  5943.             return 0
  5944.             ;;
  5945.         -lameopts)
  5946.             COMPREPLY=( $( compgen -W 'vbr= abr cbr br= q= aq= \
  5947.                     ratio= vol= mode= padding= fast \
  5948.                     preset= help' -- $cur ) )
  5949.             return 0
  5950.             ;;
  5951.         -rawaudio)
  5952.             COMPREPLY=( $( compgen -W 'on channels= rate= \
  5953.                     samplesize= format=' -- $cur ) )
  5954.             return 0
  5955.             ;;
  5956.         -rawvideo)
  5957.             COMPREPLY=( $( compgen -W 'on fps= sqcif qcif cif \
  5958.                     4cif pal ntsc w= h= y420 yv12 yuy2 \
  5959.                     y8 format= size=' -- $cur ) )
  5960.             return 0
  5961.             ;;
  5962.         -aop)
  5963.             COMPREPLY=( $( compgen -W 'list= delay= format= fout= \
  5964.                     volume= mul= softclip' -- $cur ) )
  5965.             return 0
  5966.             ;;
  5967.         -dxr2)
  5968.             COMPREPLY=( $( compgen -W 'ar-mode= iec958-encoded \
  5969.                     iec958-decoded mute ucode= 75ire bw \
  5970.                     color interlaced macrovision= norm= \
  5971.                     square-pixel ccir601-pixel cr-left= \
  5972.                     cr-right= cr-top= cr-bot= ck-rmin= \
  5973.                     ck-gmin= ck-bmin= ck-rmax= ck-gmax= \
  5974.                     ck-bmax= ck-r= ck-g= ck-b= \
  5975.                     ignore-cache= ol-osd= olh-cor= \
  5976.                     olw-cor= olx-cor= oly-cor= overlay \
  5977.                     overlay-ratio= update-cache' -- $cur ))
  5978.             return 0
  5979.             ;;
  5980.         -tv)
  5981.             COMPREPLY=( $( compgen -W 'on noaudio driver= device= \
  5982.                     input= freq= outfmt= width= height= \
  5983.                     buffersize= norm= channel= chanlist= \
  5984.                     audiorate= forceaudio alsa amode= \
  5985.                     forcechan= adevice= audioid= volume= \
  5986.                     bass= treble= balance= fps= \
  5987.                     channels= immediatemode=' -- $cur ) )
  5988.             return 0
  5989.             ;;
  5990.         -mf)
  5991.             COMPREPLY=( $( compgen -W 'on w= h= fps= type=' \
  5992.                     -- $cur ) )
  5993.             return 0
  5994.             ;;
  5995.         -cdda)
  5996.             COMPREPLY=( $( compgen -W 'speed= paranoia= \
  5997.                     generic-dev= sector-size= overlap= \
  5998.                     toc-bias toc-offset= skip noskip' \
  5999.                     -- $cur ) )
  6000.             return 0
  6001.             ;;
  6002.         -input)
  6003.             COMPREPLY=( $( compgen -W 'conf= ar-delay ar-rate \
  6004.                     keylist cmdlist js-dev file' -- $cur ) )
  6005.             return 0
  6006.             ;;
  6007.         -af)
  6008.             COMPREPLY=( $( compgen -W 'resample resample= \
  6009.                     channels channels= format format= \
  6010.                     volume volume= delay delay= pan \
  6011.                     pan= sub sub= surround surround=' \
  6012.                     -- $cur ) )
  6013.             return 0
  6014.             ;;
  6015.         -af-adv)
  6016.             COMPREPLY=( $( compgen -W 'force= list=' -- $cur ) )
  6017.             return 0
  6018.             ;;
  6019.         -profile)
  6020.             local profiles=$(sed -ne 's|\[\(.*\)\]|\1|p' ~/.mplayer/config)
  6021.             COMPREPLY=( $( compgen -W "$profiles" -- $cur))
  6022.             return 0
  6023.             ;;
  6024.     esac
  6025.  
  6026.     case "$cur" in
  6027.         -*)
  6028.             COMPREPLY=( $( compgen -W '-aid -alang -audio-demuxer \
  6029.                     -audiofile -cdrom-device -cache -cdda \
  6030.                     -channels -chapter -csslib -demuxer \
  6031.                     -dvd -dvd-device -dvdangle -dvdauth \
  6032.                     -dvdkey -dvdnav -forceidx -fps -frames \
  6033.                     -hr-mp3-seek -idx -mc -mf -ni -nobps \
  6034.                     -passwd -rawaudio -rtsp-stream-over-tcp\
  6035.                     -skipopening -sb -srate -ss -tv -user \
  6036.                     -vcd -vid -vivo -ifo -ffactor -font \
  6037.                     -noautosub -nooverlapsub -sid -slang \
  6038.                     -sub -subcc -subcp -sub-demuxer \
  6039.                     -subdelay -subfont-autoscale \
  6040.                     -subfont-blur -subfont-encoding \
  6041.                     -subfont-osd-scale -subfont-outline \
  6042.                     -subfont-text-scale -subfps -subfile \
  6043.                     -subpos -unicode -utf8 -vobsub \
  6044.                     -vobsubid -ac -afm -aspect -flip \
  6045.                     -lavdopts -noaspect -nosound -pp -ssf \
  6046.                     -stereo -sws -vc -vfm -vop -xvidopts\
  6047.                     -xy -zoom -bandwidth -cuefile \
  6048.                     -noextbased -rawvideo -overlapsub \
  6049.                     -sub-bg-alpha -sub-bg-color -subalign \
  6050.                     -subwidth -sub-no-text-pp -spualign \
  6051.                     -spuaa -spugauss -pphelp -verbose -v \
  6052.                     -noni -noidx -nohr-mp3-seek -extbased \
  6053.                     -bps -oldpp -nozoom -noflip -nounicode \
  6054.                     -noutf8 -profile -vf -af' -- $cur ) )
  6055.             # add mplayer specific options
  6056.             [[ "$cmd" == @(?(g)mplayer) ]] && COMPREPLY=( "${COMPREPLY[@]}" \
  6057.                 $(compgen -W '-autoq -autosync -benchmark \
  6058.                     -framedrop -h -help -hardframedrop \
  6059.                     -identify -input -lircconf -loop \
  6060.                     -nojoystick -nolirc -nortc -playlist \
  6061.                     -quiet -really-quiet -rnd -sdp -skin \
  6062.                     -slave -softsleep -speed -sstep \
  6063.                     -use-stdin -dumpaudio -dumpfile \
  6064.                     -dumpstream -dumpvideo -dumpmicrodvdsub\
  6065.                     -dumpmpsub -dumpsrtsub -dumpjacosub \
  6066.                     -dumpsami -dumpsub -osdlevel -af \
  6067.                     -af-adv -ao -aofile -aop -delay -mixer \
  6068.                     -nowaveheader -bpp -brightness \
  6069.                     -contrast -display -double -dr -dxr2 \
  6070.                     -fb -fbmode -fbmodeconfig -forcexv -fs \
  6071.                     -geometry -hue -icelayer -jpeg \
  6072.                     -monitor-dotclock -monitor-hfreq \
  6073.                     -monitor-vfreq -monitoraspect \
  6074.                     -nograbpointer -noslices -panscan \
  6075.                     -rootwin -saturation -screenw -screenh \
  6076.                     -stop-xscreensaver -vm -vo -vsync -wid \
  6077.                     -xineramascreen -z -zrbw -zrcrop \
  6078.                     -zrdev -zrfd -zrhelp -zrnorm -zrquality \
  6079.                     -zrvdec -zrhdec -zrxdoff -zrydoff -y \
  6080.                     -edl -edlout -enqueue -fixed-vo \
  6081.                     -menu -menu-root -menu-cfg -shuffle \
  6082.                     -format -aahelp -dfbopts -fstype \
  6083.                     -guiwid -nokeepaspect -x --help \
  6084.                     -aaosdcolor -aasubcolor -aadriver \
  6085.                     -aaextended -aaeight' -- $cur) )
  6086.             # add mencoder specific options
  6087.             [[ "$cmd" = mencoder ]] && COMPREPLY=( "${COMPREPLY[@]}" \
  6088.                 $(compgen -W '-audio-density -audio-delay \
  6089.                     -audio-preload -divx4opts -endpos \
  6090.                     -ffourcc -include -info -lameopts \
  6091.                     -lavcopts -noskip -o -oac -ofps -ovc \
  6092.                     -passlogfile -skiplimit -vobsubout \
  6093.                     -vobsuboutindex -vobsuboutid \
  6094.                     -xvidencopts -of --verbose' -- $cur) )
  6095.             ;;
  6096.         *)
  6097.             _filedir '@(mp?(e)g|MP?(E)G|wm[av]|WM[AV]|avi|AVI|asf|ASF|vob|VOB|bin|BIN|dat|DAT|vcd|VCD|ps|PS|pes|PES|fl[iv]|FL[IV]|viv|VIV|rm?(j)|RM?(J)|ra?(m)|RA?(M)|yuv|YUV|mov|MOV|qt|QT|mp[34]|MP[34]|m4[av]|M4[AV]|og[gm]|OG[GM]|w?(a)v|W?(A)V|dump|DUMP|mk[av]|MK[AV]|m4a|M4A|aac|AAC|m2v|M2V|dv|DV|rmvb|RMVB|mid|MID|ts|TS|3g[p2]|mpc|MPC|flac|FLAC|vro|VRO|divx|DIVX|aif?(f)|AIF?(F)|m2ts|M2TS)'
  6098.             ;;
  6099.     esac
  6100.  
  6101.     return 0
  6102. }
  6103. complete $filenames -F _mplayer mplayer mencoder gmplayer kplayer
  6104. }
  6105.  
  6106. # KDE dcop completion
  6107. #
  6108. have dcop &&
  6109. _dcop()
  6110. {
  6111.     local cur compstr
  6112.  
  6113.     COMPREPLY=()
  6114.     cur=`_get_cword`
  6115.     if [ -z $cur ]; then
  6116.         compstr=${COMP_WORDS[*]}
  6117.     else
  6118.         compstr=$( command echo ${COMP_WORDS[*]} | sed "s/ $cur$//" )
  6119.     fi
  6120.     COMPREPLY=( $( compgen -W '$( command $compstr | sed s/\(.*\)// )'  -- $cur ) )
  6121. } &&
  6122. complete -F _dcop dcop
  6123.  
  6124. # Qt qdbus completion
  6125. #
  6126. have qdbus &&
  6127. _qdbus()
  6128. {
  6129.         local cur compstr
  6130.  
  6131.         COMPREPLY=()
  6132.         cur=`_get_cword`
  6133.         if [ -z $cur ]; then
  6134.             compstr=${COMP_WORDS[*]}
  6135.         else
  6136.             compstr=$( command echo ${COMP_WORDS[*]} | sed "s/ ${cur/\//\\/}$//" )
  6137.         fi
  6138.         COMPREPLY=( $( compgen -W '$( command $compstr | sed s/\(.*\)// )'  -- $cur ) )
  6139. } &&
  6140. complete -F _qdbus qdbus
  6141.  
  6142. # wvdial(1) completion
  6143. #
  6144. have wvdial &&
  6145. _wvdial()
  6146. {
  6147.     local cur prev config i IFS=$'\t\n'
  6148.  
  6149.     COMPREPLY=()
  6150.     cur=`_get_cword`
  6151.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6152.  
  6153.     case $prev in
  6154.         --config)
  6155.             _filedir
  6156.             return 0
  6157.             ;;
  6158.     esac
  6159.  
  6160.     case $cur in
  6161.         -*)
  6162.             COMPREPLY=( $( compgen -W '--config --chat \
  6163.                 --remotename --help --version --no-syslog' \
  6164.                 -- $cur ) )
  6165.             ;;
  6166.         *)
  6167.             # start with global and personal config files
  6168.                    config="/etc/wvdial.conf"$'\t'"$HOME/.wvdialrc"
  6169.             # replace with command line config file if present
  6170.             for (( i=1; i < COMP_CWORD; i++ )); do
  6171.                 if [[ "${COMP_WORDS[i]}" == "--config" ]]; then
  6172.                     config=${COMP_WORDS[i+1]}
  6173.                     break
  6174.                 fi
  6175.             done
  6176.             # parse config files for sections and
  6177.             # remove default section
  6178.             COMPREPLY=( $( sed -ne \
  6179.                     "s|^\[Dialer \($cur.*\)\]$|\1|p" \
  6180.                     $config 2>/dev/null |grep -v '^Defaults$'))
  6181.             # escape spaces
  6182.             COMPREPLY=${COMPREPLY// /\\ }
  6183.             ;;
  6184.     esac
  6185.  
  6186. } &&
  6187. complete -F _wvdial wvdial
  6188.  
  6189. # gpg(1) completion
  6190. #
  6191. have gpg &&
  6192. _gpg()
  6193. {
  6194.     local cur prev
  6195.  
  6196.     COMPREPLY=()
  6197.     cur=`_get_cword`
  6198.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6199.  
  6200.     case "$prev" in
  6201.     -@(s|-sign|-clearsign|-decrypt-files|-load-extension))
  6202.         _filedir
  6203.         return 0
  6204.         ;;
  6205.     --@(export|@(?(l|nr|nrl)sign|edit)-key))
  6206.         # return list of public keys
  6207.         COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*/\([^ ]*\).*\(<\([^>]*\)>\).*$@\1 \3@p')" -- "$cur" ))
  6208.         return 0
  6209.         ;;
  6210.     -@(r|-recipient))
  6211.         COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | sed -ne 's@^pub.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ))
  6212.         if [ -e ~/.gnupg/gpg.conf ]; then
  6213.             COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$( sed -ne 's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' ~/.gnupg/gpg.conf  )" -- "$cur") )
  6214.         fi
  6215.         return 0
  6216.         ;;
  6217.     esac
  6218.  
  6219.     if [[ "$cur" == -* ]]; then
  6220.         COMPREPLY=( $( compgen -W '-s -b -e -f -c -d -a -r -u -Z -o -v\
  6221.                 -q -n -N $(gpg --dump-options)' -- $cur ) )
  6222.      fi
  6223.  
  6224. } &&
  6225. complete -F _gpg $default gpg
  6226.  
  6227. # iconv(1) completion
  6228. #
  6229. have iconv &&
  6230. _iconv()
  6231. {
  6232.     local cur prev
  6233.  
  6234.     COMPREPLY=()
  6235.     cur=`_get_cword`
  6236.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6237.  
  6238.     case "$prev" in
  6239.         -@(f|t|-@(from|to)-code))
  6240.             COMPREPLY=( $( compgen -W \
  6241.                 '$( iconv --list | sed -e "s@//@@;" )' -- "$cur" ) )
  6242.             return 0
  6243.             ;;
  6244.     esac
  6245.  
  6246.  
  6247.     if [[ "$cur" = -* ]]; then
  6248.         COMPREPLY=( $( compgen -W '--from-code -f --to-code -t --list
  6249.         --output -o --verbose' -- "$cur" ) )
  6250.         return 0
  6251.     fi
  6252. } &&
  6253. complete -F _iconv $default iconv
  6254.  
  6255. # dict(1) completion
  6256. #
  6257. { have dict || have rdict; } && {
  6258. _dictdata()
  6259. {
  6260.     dict $host $port $1 2>/dev/null | sed -ne \
  6261.         's/^['$'\t '']['$'\t '']*\([^'$'\t '']*\).*$/\1/p'
  6262. }
  6263.  
  6264. _dict()
  6265. {
  6266.     local cur prev host port db dictfile
  6267.  
  6268.     COMPREPLY=()
  6269.     cur=`_get_cword`
  6270.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6271.     dictfile=/usr/share/dict/words
  6272.  
  6273.     for (( i=1; i < COMP_CWORD; i++ )); do
  6274.         case "${COMP_WORDS[i]}" in
  6275.         -@(h|--host))
  6276.             host=${COMP_WORDS[i+1]}
  6277.             [ -n "$host" ] && host="-h $host"
  6278.             i=$((++i))
  6279.             ;;
  6280.         -@(p|-port))
  6281.             port=${COMP_WORDS[i+1]}
  6282.             [ -n "$port" ] && port="-p $port"
  6283.             i=$((++i))
  6284.             ;;
  6285.         -@(d|-database))
  6286.             db=${COMP_WORDS[i+1]}
  6287.             [ -n "$db" ] && host="-d $db"
  6288.             i=$((++i))
  6289.             ;;
  6290.         *)
  6291.             ;;
  6292.         esac
  6293.     done
  6294.  
  6295.     if [[ "$cur" = -* ]]; then
  6296.         COMPREPLY=( $( compgen -W '-h --host -p --port -d --database \
  6297.                    -m --match -s --strategy -c --config -C \
  6298.                    --nocorrect -D --dbs -S --strats -H \
  6299.                    --serverhelp -i --info -I --serverinfo \
  6300.                    -a --noauth -u --user -k --key -V --version \
  6301.                    -L --license --help -v --verbose -r --raw \
  6302.                    -P --pager --debug --html --pipesize --client' \
  6303.                    -- "$cur" ) )
  6304.         return 0
  6305.     fi
  6306.  
  6307.     case "$prev" in
  6308.     -@(d|-database|i|info))
  6309.         COMPREPLY=( $( compgen -W '$( _dictdata -D )' -- "$cur" ) )
  6310.         return 0
  6311.         ;;
  6312.     -@(s|-strategy))
  6313.         COMPREPLY=( $( compgen -W '$( _dictdata -S )' -- "$cur" ) )
  6314.         return 0
  6315.         ;;
  6316.     *)
  6317.         ;;
  6318.     esac
  6319.  
  6320.     [ -r $dictfile ] && \
  6321.         COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) )
  6322. }
  6323. complete -F _dict $default dict rdict
  6324. }
  6325.  
  6326. # cdrecord(1) completion
  6327. #
  6328. have cdrecord &&
  6329. _cdrecord()
  6330. {
  6331.     local cur prev i generic_options track_options track_mode
  6332.  
  6333.     COMPREPLY=()
  6334.     cur=`_get_cword`
  6335.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6336.  
  6337.     # foo=bar style option
  6338.     if [[ "$cur" == *=* ]]; then
  6339.         prev=${cur/=*/}
  6340.         cur=${cur/*=/}
  6341.         case "$prev" in
  6342.             @(text|cue)file)
  6343.                 _filedir
  6344.                 return 0
  6345.                 ;;
  6346.             blank)
  6347.                 COMPREPLY=( $( compgen -W 'help all fast \
  6348.                 track unreserve trtail unclose session' \
  6349.                 -- $cur ) )
  6350.                 return 0
  6351.                 ;;
  6352.             driveropts)
  6353.                 COMPREPLY=( $( compgen -W 'burnfree noburnfree\
  6354.                   varirec= audiomaster forcespeed noforcespeed\
  6355.                   speedread nospeedread singlesession \
  6356.                   nosinglesession hidecdr nohidecdr tattooinfo\
  6357.                   tattoofile=' -- $cur ) )
  6358.                 return 0
  6359.                 ;;
  6360.         esac
  6361.     fi
  6362.  
  6363.     generic_options=(-version -v -V -d -silent -s -force -immed -dummy \
  6364.              -dao -raw -raw96r -raw96p -raw16 -multi -msinfo -toc \
  6365.              -atip -fix -nofix -waiti -load -lock -eject -format \
  6366.              -setdropts -checkdrive -prcap -inq -scanbus -reset \
  6367.              -abort -overburn -ignsize -useinfo -packet -noclose \
  6368.              -text debug= kdebug= kd= minbuf= speed= blank= fs= \
  6369.              dev= gracetime= timeout= driver= driveropts= \
  6370.              defpregap= pktsize= mcn= textfile= cuefile=)
  6371.     track_options=(-audio -swab -data -mode2 -xa -xa1 -xa2 -xamix -cdi \
  6372.                -isosize -pad padsize= -nopad -shorttrack -noshorttrack\
  6373.                pregap= -preemp -nopreemp -copy -nocopy -scms tcsize= \
  6374.                isrc= index=)
  6375.     # look if previous was either a file or a track option
  6376.     track_mode=0
  6377.     if [ $COMP_CWORD -gt 1 ]; then
  6378.         if [ -f "$prev" ]; then
  6379.             track_mode=1
  6380.         else
  6381.             for (( i=0; i < ${#track_options[@]}; i++ )); do
  6382.                 if [[ "${track_options[i]}" == "$prev" ]]; then
  6383.                     track_mode=1
  6384.                     break
  6385.                 fi
  6386.             done
  6387.         fi
  6388.     fi
  6389.  
  6390.     # files are always eligible completion
  6391.     _filedir
  6392.     # track options are always available
  6393.     COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W '${track_options[@]}' -- $cur ) )
  6394.     # general options are no more available after file or track option
  6395.     if [ $track_mode -eq 0 ]; then
  6396.         COMPREPLY=( "${COMPREPLY[@]}" \
  6397.                 $( compgen -W '${generic_options[@]}' -- $cur ) )
  6398.     fi
  6399.  
  6400. } &&
  6401. complete -F _cdrecord $filenames cdrecord
  6402.  
  6403. # mkisofs(8) completion
  6404. #
  6405. have mkisofs &&
  6406. _mkisofs()
  6407. {
  6408.     local cur prev
  6409.  
  6410.     COMPREPLY=()
  6411.     cur=`_get_cword`
  6412.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6413.  
  6414.     case "$prev" in
  6415.         -@(o|abstract|biblio|check-session|copyright|log-file|root-info|prep-boot|*-list))
  6416.             _filedir
  6417.             return 0
  6418.             ;;
  6419.         -*-charset)
  6420.             COMPREPLY=( $( mkisofs -input-charset help 2>&1 | \
  6421.                     tail +3 | grep "^$cur") )
  6422.             return 0
  6423.             ;;
  6424.         -uid)
  6425.             _uids
  6426.             return 0
  6427.             ;;
  6428.         -gid)
  6429.             _gids
  6430.             return 0
  6431.             ;;
  6432.     esac
  6433.  
  6434.     if [[ "$cur" == -* ]]; then
  6435.         COMPREPLY=( $( compgen -W '-abstract -A -allow-lowercase \
  6436.                 -allow-multidot -biblio -cache-inodes \
  6437.                 -no-cache-inodes -b -eltorito-alt-boot -B -G \
  6438.                 -hard-disk-boot -no-emul-boot -no-boot \
  6439.                 -boot-load-seg -boot-load-size \
  6440.                 -boot-info-table -C -c -check-oldname \
  6441.                 -check-session -copyright -d -D -dir-mode \
  6442.                 -dvd-video -f -file-mode -gid -gui \
  6443.                 -graft-points -hide -hide-list -hidden \
  6444.                 -hidden-list -hide-joliet -hide-joliet-list \
  6445.                 -hide-joliet-trans-tbl -hide-rr-moved \
  6446.                 -input-charset -output-charset -iso-level -J \
  6447.                 -joliet-long -jcharset -l -L -log-file -m \
  6448.                 -exclude-list -max-iso9660-filenames -M -N \
  6449.                 -new-dir-mode -nobak -no-bak -force-rr -no-rr \
  6450.                 -no-split-symlink-components \
  6451.                 -no-split-symlink-fields -o -pad -no-pad \
  6452.                 -path-list -P -p -print-size -quiet -R -r \
  6453.                 -relaxed-filenames -sort -split-output \
  6454.                 -stream-media-size -stream-file-name -sysid -T\
  6455.                 -table-name -ucs-level -udf -uid \
  6456.                 -use-fileversion -U -no-iso-translate -V \
  6457.                 -volset -volset-size -volset-seqno -v -x -z \
  6458.                 -hfs -apple -map -magic -hfs-creator \
  6459.                 -hfs-type -probe -no-desktop -mac-name \
  6460.                 -boot-hfs-file -part -auto -cluster-size \
  6461.                 -hide-hfs -hide-hfs-list -hfs-volid \
  6462.                 -icon-position -root-info -prep-boot \
  6463.                 -input-hfs-charset -output-hfs-charset \
  6464.                 -hfs-unlock -hfs-bless -hfs-parms --cap \
  6465.                 --netatalk --double --ethershare --ushare \
  6466.                 --exchange --sgi --xinet --macbin --single \
  6467.                 --dave --sfm --osx-double --osx-hfs' -- $cur ))
  6468.     else
  6469.         _filedir
  6470.     fi
  6471.  
  6472. } &&
  6473. complete -F _mkisofs $filenames mkisofs
  6474.  
  6475. # mc(1) completion
  6476. #
  6477. have mc &&
  6478. _mc()
  6479. {
  6480.     local cur prev
  6481.  
  6482.     COMPREPLY=()
  6483.     cur=`_get_cword`
  6484.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6485.  
  6486.     # -name value style option
  6487.     case "$prev" in
  6488.         -@(e|v|l|P))
  6489.             _filedir
  6490.             return 0
  6491.             ;;
  6492.     esac
  6493.  
  6494.     # --name=value style option
  6495.     if [[ "$cur" == *=* ]]; then
  6496.         prev=${cur/=*/}
  6497.         cur=${cur/*=/}
  6498.         case "$prev" in
  6499.             --@(edit|view|ftplog|printwd))
  6500.                 _filedir
  6501.                 return 0
  6502.                 ;;
  6503.         esac
  6504.     fi
  6505.  
  6506.     if [[ "$cur" == -* ]]; then
  6507.         COMPREPLY=( $( compgen -W '-a --stickchars -b --nocolor -c \
  6508.             --color -C --colors= -d --nomouse -e --edit= -f \
  6509.             --datadir -k --resetsoft -l --ftplog= -P --printwd= \
  6510.             -s --slow -t --termcap -u --nosubshell -U --subshell \
  6511.             -v --view= -V --version -x --xterm -h --help' -- $cur ) )
  6512.     else
  6513.         _filedir -d
  6514.     fi
  6515. } &&
  6516. complete -F _mc $filenames mc
  6517.  
  6518. # yum(8) completion
  6519. #
  6520. have yum && {
  6521. _yum()
  6522. {
  6523.     local cur prev special
  6524.  
  6525.     COMPREPLY=()
  6526.     cur=`_get_cword`
  6527.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6528.  
  6529.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  6530.         if [[ ${COMP_WORDS[i]} == @(install|update|upgrade|remove|erase|deplist) ]]; then
  6531.             special=${COMP_WORDS[i]}
  6532.         fi
  6533.     done
  6534.  
  6535.     if [ -n "$special" ]; then
  6536.         case $special in
  6537.         install|deplist)
  6538.             COMPREPLY=( $( compgen -W '$( yum -C list | cut -d" " -f1 )' -- $cur ) )
  6539.             return 0
  6540.             ;;
  6541.         *)
  6542.             _rpm_installed_packages
  6543.             return 0
  6544.             ;;
  6545.         esac
  6546.     fi
  6547.  
  6548.     case $cur in
  6549.         --*)
  6550.         COMPREPLY=( $( compgen -W '--installroot --version --help --enablerepo --disablerepo --exclude --obsoletes --noplugins' -- $cur ) )
  6551.         return 0
  6552.         ;;
  6553.         -*)
  6554.         COMPREPLY=( $( compgen -W '-c -e -d -y -t -R -C -h' -- $cur ) )
  6555.         return 0
  6556.         ;;
  6557.     esac
  6558.  
  6559.     case $prev in
  6560.         list)
  6561.         COMPREPLY=( $( compgen -W 'all available updates installed extras obsoletes recent' -- $cur ) )
  6562.         ;;
  6563.         clean)
  6564.         COMPREPLY=( $( compgen -W 'packages headers metadata cache dbcache all' -- $cur ) )
  6565.         ;;
  6566.         localinstall)
  6567.         _filedir rpm
  6568.         ;;
  6569.         -c)
  6570.         _filedir
  6571.         ;;
  6572.         --installroot)
  6573.         _filedir -d
  6574.         ;;
  6575.         *)
  6576.         COMPREPLY=( $( compgen -W 'install update check-update upgrade remove list \
  6577.                         search info provides clean groupinstall groupupdate \
  6578.                         grouplist deplist erase groupinfo groupremove \
  6579.                         localinstall localupdate makecache resolvedep \
  6580.                         shell whatprovides' -- $cur ) )
  6581.         ;;
  6582.     esac
  6583. }
  6584. complete -F _yum $filenames yum
  6585.  
  6586. # yum-arch(8) completion
  6587. #
  6588. _yum_arch()
  6589. {
  6590.     local cur
  6591.     COMPREPLY=()
  6592.     cur=`_get_cword`
  6593.  
  6594.     case "$cur" in
  6595.     -*)
  6596.         COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- $cur ) )
  6597.         ;;
  6598.     *)
  6599.         _filedir -d
  6600.         ;;
  6601.     esac
  6602.  
  6603.     return 0
  6604.  
  6605. }
  6606. complete -F _yum_arch $filenames yum-arch
  6607. }
  6608.  
  6609. # ImageMagick completion
  6610. #
  6611. have convert && {
  6612. _ImageMagick()
  6613. {
  6614.     local prev
  6615.     prev=${COMP_WORDS[COMP_CWORD-1]}
  6616.  
  6617.     case "$prev" in
  6618.         -channel)
  6619.             COMPREPLY=( $( compgen -W 'Red Green Blue Opacity \
  6620.                 Matte Cyan Magenta Yellow Black' -- $cur ) )
  6621.             return 0
  6622.             ;;
  6623.         -colormap)
  6624.             COMPREPLY=( $( compgen -W 'shared private' -- $cur ) )
  6625.             return 0
  6626.             ;;
  6627.         -colorspace)
  6628.             COMPREPLY=( $( compgen -W 'GRAY OHTA RGB Transparent \
  6629.                 XYZ YCbCr YIQ YPbPr YUV CMYK' -- $cur ) )
  6630.             return 0
  6631.             ;;
  6632.         -compose)
  6633.             COMPREPLY=( $( compgen -W 'Over In Out Atop Xor Plus \
  6634.                 Minus Add Subtract Difference Multiply Bumpmap\
  6635.                 Copy CopyRed CopyGreen CopyBlue CopyOpacity' \
  6636.                 -- $cur ) )
  6637.             return 0
  6638.             ;;
  6639.         -compress)
  6640.             COMPREPLY=( $( compgen -W 'None BZip Fax Group4 JPEG \
  6641.                 Lossless LZW RLE Zip' -- $cur ) )
  6642.             return 0
  6643.             ;;
  6644.         -dispose)
  6645.             COMPREPLY=( $( compgen -W 'Undefined None Background \
  6646.                             Previous' -- $cur ) )
  6647.             return 0
  6648.             ;;
  6649.         -encoding)
  6650.             COMPREPLY=( $( compgen -W 'AdobeCustom AdobeExpert \
  6651.                 AdobeStandard AppleRoman BIG5 GB2312 Latin2 \
  6652.                 None SJIScode Symbol Unicode Wansung' -- $cur))
  6653.             return 0
  6654.             ;;
  6655.         -endian)
  6656.             COMPREPLY=( $( compgen -W 'MSB LSB' -- $cur ) )
  6657.             return 0
  6658.             ;;
  6659.         -filter)
  6660.             COMPREPLY=( $( compgen -W 'Point Box Triangle Hermite \
  6661.                 Hanning Hamming Blackman Gaussian Quadratic \
  6662.                 Cubic Catrom Mitchell Lanczos Bessel Sinc' \
  6663.                 -- $cur ) )
  6664.             return 0
  6665.             ;;
  6666.         -format)
  6667.             COMPREPLY=( $( convert -list format | \
  6668.                     awk '/ [r-][w-][+-] / {print $1}' | \
  6669.                     tr -d '*' | tr [:upper:] [:lower:] | \
  6670.                     grep "^$cur" ) )
  6671.             return 0
  6672.             ;;
  6673.         -gravity)
  6674.             COMPREPLY=( $( compgen -W 'Northwest North NorthEast \
  6675.                 West Center East SouthWest South SouthEast' \
  6676.                 -- $cur ) )
  6677.             return 0
  6678.             ;;
  6679.         -intent)
  6680.             COMPREPLY=( $( compgen -W 'Absolute Perceptual \
  6681.                     Relative Saturation' -- $cur ) )
  6682.             return 0
  6683.             ;;
  6684.         -interlace)
  6685.             COMPREPLY=( $( compgen -W 'None Line Plane Partition' \
  6686.                     -- $cur ) )
  6687.             return 0
  6688.             ;;
  6689.         -limit)
  6690.             COMPREPLY=( $( compgen -W 'Disk File Map Memory' \
  6691.                     -- $cur ) )
  6692.             return 0
  6693.             ;;
  6694.         -list)
  6695.             COMPREPLY=( $( compgen -W 'Delegate Format Magic \
  6696.                     Module Resource Type' -- $cur ) )
  6697.             return 0
  6698.             ;;
  6699.         -map)
  6700.             COMPREPLY=( $( compgen -W 'best default gray red \
  6701.                     green blue' -- $cur ) )
  6702.             _filedir
  6703.             return 0
  6704.             ;;
  6705.         -noise)
  6706.             COMPREPLY=( $( compgen -W 'Uniform Gaussian \
  6707.                     Multiplicative \
  6708.                 Impulse Laplacian Poisson' -- $cur ) )
  6709.             return 0
  6710.             ;;
  6711.         -preview)
  6712.             COMPREPLY=( $( compgen -W 'Rotate Shear Roll Hue \
  6713.                     Saturation Brightness Gamma Spiff \
  6714.                     Dull Grayscale Quantize Despeckle \
  6715.                     ReduceNoise AddNoise Sharpen Blur \
  6716.                     Treshold EdgeDetect Spread Shade \
  6717.                     Raise Segment Solarize Swirl Implode \
  6718.                     Wave OilPaint CharcoalDrawing JPEG' \
  6719.                     -- $cur ) )
  6720.             return 0
  6721.             ;;
  6722.         -@(mask|profile|texture|tile|write))
  6723.             _filedir
  6724.             return 0
  6725.             ;;
  6726.         -type)
  6727.             COMPREPLY=( $( compgen -W 'Bilevel Grayscale Palette \
  6728.                     PaletteMatte TrueColor TrueColorMatte \
  6729.                     ColorSeparation ColorSeparationlMatte \
  6730.                     Optimize' -- $cur ) )
  6731.             return 0
  6732.             ;;
  6733.         -units)
  6734.             COMPREPLY=( $( compgen -W 'Undefined PixelsPerInch \
  6735.                     PixelsPerCentimeter' -- $cur ) )
  6736.             return 0
  6737.             ;;
  6738.         -virtual-pixel)
  6739.             COMPREPLY=( $( compgen -W 'Constant Edge mirror tile' \
  6740.                     -- $cur ) )
  6741.             return 0
  6742.             ;;
  6743.         -visual)
  6744.             COMPREPLY=( $( compgen -W 'StaticGray GrayScale \
  6745.                     StaticColor PseudoColor TrueColor \
  6746.                     DirectColor defaut visualid' -- $cur ))
  6747.             return 0
  6748.             ;;
  6749.     esac
  6750. }
  6751.  
  6752. _convert()
  6753. {
  6754.     local cur
  6755.  
  6756.     COMPREPLY=()
  6757.     cur=`_get_cword`
  6758.  
  6759.     _ImageMagick
  6760.  
  6761.     if [[ "$cur" == -* ]]; then
  6762.         COMPREPLY=( $( compgen -W '-adaptive-blur -adaptive-resize \
  6763.             -adaptive-sharpen -adjoin -affine -alpha -annotate \
  6764.             -antialias -append -attenuate -authenticate \
  6765.             -auto-orient -average -background -bench -bias \
  6766.             -black-point-compensation -black-threshold \
  6767.             -blue-primary -blur -border -bordercolor -caption \
  6768.             -channel -charcoal -chop -clip -clip-mask -clip-path \
  6769.             -clone -clut -coalesce -colorize -colors -colorspace \
  6770.             -combine -comment -compose -composite -compress \
  6771.             -contrast -contrast-stretch -convolve -crop -cycle \
  6772.             -debug -decipher -deconstruct -define -delay -delete \
  6773.             -density -depth -despeckle -display -dispose -distort \
  6774.             -dither -draw -edge -emboss -encipher -encoding \
  6775.             -endian -enhance -equalize -evaluate -extent -extract \
  6776.             -family -fill -filter -flatten -flip -floodfill -flop \
  6777.             -font -format -frame -fuzz -fx -gamma -gaussian-blur \
  6778.             -geometry -gravity -green-primary -help -identify \
  6779.             -implode -insert -intent -interlace -interpolate \
  6780.             -label -lat -layers -level -limit -linear-stretch \
  6781.             -liquid-rescale -list -log -loop -map -mask \
  6782.             -mattecolor -median -modulate -monitor -monochrome \
  6783.             -morph -mosaic -motion-blur -negate -noise -normalize \
  6784.             -opaque -ordered-dither -orient -page -paint -ping \
  6785.             -pointsize -polaroid -posterize -preview -print \
  6786.             -process -profile -quality -quantize -quiet \
  6787.             -radial-blur -raise -random-threshold -recolor \
  6788.             -red-primary -regard-warnings -region -render -repage \
  6789.             -resample -resize -respect-parenthesis -reverse -roll \
  6790.             -rotate -sample -sampling-factor -scale -scene -seed \
  6791.             -segment -separate -sepia-tone -set -shade -shadow \
  6792.             -sharpen -shave -shear -sigmoidal-contrast -size \
  6793.             -sketch -solarize -splice -spread -stretch -strip \
  6794.             -stroke -strokewidth -style -swap -swirl -taint \
  6795.             -texture -threshold -thumbnail -tile -tile-offset \
  6796.             -tint -transform -transparent -transparent-color \
  6797.             -transpose -transverse -treedepth -trim -type \
  6798.             -undercolor -unique-colors -units -unsharp -verbose \
  6799.             -version -view -vignette -virtual-pixel -wave \
  6800.             -weight -white-point -white-threshold \
  6801.             -write' -- $cur ) )
  6802.     elif [[ "$cur" == +* ]]; then
  6803.         COMPREPLY=( $( compgen -W '+adjoin +append +compress \
  6804.             +contrast +debug +dither +endian +gamma +label +map \
  6805.             +mask +matte +negate +noise +page +raise +render \
  6806.             +write' -- $cur ) )
  6807.     else
  6808.         _filedir
  6809.     fi
  6810. }
  6811. complete -F _convert $filenames convert
  6812.  
  6813. _mogrify()
  6814. {
  6815.     local cur
  6816.  
  6817.     COMPREPLY=()
  6818.     cur=`_get_cword`
  6819.  
  6820.     _ImageMagick
  6821.  
  6822.     if [[ "$cur" == -* ]]; then
  6823.         COMPREPLY=( $( compgen -W '-adaptive-blur -adaptive-resize \
  6824.             -adaptive-sharpen -adjoin -affine -alpha -annotate \
  6825.             -antialias -attenuate -authenticate -auto-orient \
  6826.             -background -bias -black-point-compensation \
  6827.             -black-threshold -blue-primary -blur -border \
  6828.             -bordercolor -caption -channel -charcoal -chop -clip \
  6829.             -clip-mask -clip-path -clut -colorize -colors \
  6830.             -colorspace -comment -compose -compress -contrast \
  6831.             -contrast-stretch -convolve -cycle -debug -decipher \
  6832.             -define -delay -density -depth -despeckle -display \
  6833.             -dispose -distort -dither -draw -edge -emboss \
  6834.             -encipher -encoding -endian -enhance -equalize \
  6835.             -evaluate -extent -extract -family -fill -filter \
  6836.             -flip -floodfill -flop -font -format -frame -fuzz \
  6837.             -gamma -gaussian-blur -geometry -gravity \
  6838.             -green-primary -help -identify -implode -intent \
  6839.             -interlace -interpolate -label -lat -layers -level \
  6840.             -limit -linear-stretch -liquid-rescale -list -log \
  6841.             -loop -mask -mattecolor -median -modulate -monitor \
  6842.             -monochrome -motion-blur -negate -noise -normalize \
  6843.             -opaque -ordered-dither -orient -page -paint -path \
  6844.             -ping -pointsize -polaroid -posterize -preview -print \
  6845.             -profile -quality -quantize -quiet -radial-blur \
  6846.             -raise -random-threshold -recolor -red-primary \
  6847.             -regard-warnings -region -render -repage -resample \
  6848.             -resize -roll -rotate -sample -sampling-factor -scale \
  6849.             -scene -seed -segment -sepia-tone -set -shade -shadow \
  6850.             -sharpen -shave -shear -sigmoidal-contrast -size \
  6851.             -sketch -solarize -splice -spread -stretch -strip \
  6852.             -stroke -strokewidth -style -swirl -taint -texture \
  6853.             -threshold -thumbnail -tile -tile-offset -tint \
  6854.             -transform -transparent -transparent-color -transpose \
  6855.             -transverse -treedepth -trim -type -undercolor \
  6856.             -unique-colors -units -unsharp -verbose -version \
  6857.             -view -vignette -virtual-pixel -wave -weight \
  6858.             -white-point -white-threshold' -- $cur ) )
  6859.     elif [[ "$cur" == +* ]]; then
  6860.         COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \
  6861.             +endian +gamma +label +map +mask +matte +negate +page \
  6862.             +raise' -- $cur ) )
  6863.     else
  6864.         _filedir
  6865.     fi
  6866. }
  6867. complete -F _mogrify $filenames mogrify
  6868.  
  6869. _display()
  6870. {
  6871.     local cur
  6872.  
  6873.     COMPREPLY=()
  6874.     cur=`_get_cword`
  6875.  
  6876.     _ImageMagick
  6877.  
  6878.     if [[ "$cur" == -* ]]; then
  6879.         COMPREPLY=( $( compgen -W '-alpha -antialias -authenticate \
  6880.             -auto-orient -backdrop -background -border \
  6881.             -bordercolor -borderwidth -borderwidth -channel -clip \
  6882.             -clip-path -coalesce -colormap -colors -colorspace \
  6883.             -comment -compress -contrast -crop -debug -decipher \
  6884.             -define -delay -density -depth -despeckle -display \
  6885.             -dispose -dither -edge -endian -enhance -extract \
  6886.             -filter -flatten -flip -flop -font -foreground \
  6887.             -format -frame -gamma -geometry -help -iconGeometry \
  6888.             -iconic -identify -immutable -interlace -interpolate \
  6889.             -label -limit -list -log -loop -map -mattecolor \
  6890.             -monitor -monochrome -name -negate -page -profile \
  6891.             -quality -quantize -quiet -raise -regard-warnings \
  6892.             -remote -repage -resample -resize \
  6893.             -respect-parenthesis -roll -rotate -sample \
  6894.             -sampling-factor -scenes -seed -segment -set \
  6895.             -shared-memory -sharpen -size -strip -texture -title \
  6896.             -transparent-color -treedepth -trim -update \
  6897.             -usePixmap -verbose -version -virtual-pixel -visual \
  6898.             -window -window-group -write' -- $cur ) )
  6899.     elif [[ "$cur" == +* ]]; then
  6900.         COMPREPLY=( $( compgen -W '+compress +contrast +debug +dither \
  6901.             +endian +gamma +label +map +matte +negate +page \
  6902.             +raise +write' -- $cur ) )
  6903.     else
  6904.         _filedir
  6905.     fi
  6906. }
  6907. complete -F _display $filenames display
  6908.  
  6909. _animate()
  6910. {
  6911.     local cur
  6912.  
  6913.     COMPREPLY=()
  6914.     cur=`_get_cword`
  6915.  
  6916.     _ImageMagick
  6917.  
  6918.     if [[ "$cur" == -* ]]; then
  6919.         COMPREPLY=( $( compgen -W '-alpha -authenticate -backdrop \
  6920.             -background -bordercolor -borderwidth -channel \
  6921.             -coalesce -colormap -colors -colorspace -crop -debug \
  6922.             -decipher -define -delay -density -depth -display \
  6923.             -dispose -dither -extract -filter -flatten -font \
  6924.             -foreground -format -gamma -geometry -help \
  6925.             -iconGeometry -iconic -identify -immutable -interlace \
  6926.             -interpolate -limit -list -log -loop -map -mattecolor \
  6927.             -mattecolor -monitor -monochrome -name -page -pause \
  6928.             -quantize -quiet -regard-warnings -remote -repage \
  6929.             -resample -resize -respect-parenthesis -rotate \
  6930.             -sampling-factor -scenes -seed -set -shared-memory \
  6931.             -size -strip -title -transparent-color -treedepth \
  6932.             -trim -verbose -version -virtual-pixel -visual \
  6933.             -window' -- $cur ) )
  6934.     elif [[ "$cur" == +* ]]; then
  6935.         COMPREPLY=( $( compgen -W '+debug +dither +gamma +map +matte' -- $cur ) )
  6936.     else
  6937.         _filedir
  6938.     fi
  6939. }
  6940. complete -F _animate $filenames animate
  6941.  
  6942. _identify()
  6943. {
  6944.     local cur
  6945.  
  6946.     COMPREPLY=()
  6947.     cur=`_get_cword`
  6948.  
  6949.     _ImageMagick
  6950.  
  6951.     if [[ "$cur" == -* ]]; then
  6952.         COMPREPLY=( $( compgen -W '-alpha -antialias -authenticate \
  6953.             -channel -colorspace -crop -debug -define -density \
  6954.             -depth -extract -format -fuzz -gamma -help -interlace \
  6955.             -interpolate -limit -list -log -monitor -ping -quiet \
  6956.             -regard-warnings -respect-parenthesis \
  6957.             -sampling-factor -seed -set -size -strip -units \
  6958.             -verbose -version -virtual-pixel' -- $cur ) )
  6959.     elif [[ "$cur" == +* ]]; then
  6960.         COMPREPLY=( $( compgen -W '+debug' -- $cur ) )
  6961.     else
  6962.         _filedir
  6963.     fi
  6964. }
  6965. complete -F _identify $filenames identify
  6966.  
  6967. _montage()
  6968. {
  6969.     local cur
  6970.  
  6971.     COMPREPLY=()
  6972.     cur=`_get_cword`
  6973.  
  6974.     _ImageMagick
  6975.  
  6976.     if [[ "$cur" == -* ]]; then
  6977.         COMPREPLY=( $( compgen -W '-adjoin -affine -alpha \
  6978.             -authenticate -background -blue-primary -blur -border \
  6979.             -bordercolor -borderwidth -caption -channel -clone \
  6980.             -coalesce -colors -colorspace -comment -compose \
  6981.             -compress -crop -debug -define -density -depth \
  6982.             -display -dispose -dither -draw -encoding -endian \
  6983.             -extract -fill -filter -flatten -flip -flop -font \
  6984.             -format -frame -gamma -geometry -gravity \
  6985.             -green-primary -help -identify -interlace \
  6986.             -interpolate -label -limit -list -log -mattecolor \
  6987.             -mode -monitor -monochrome -origin -page -pointsize \
  6988.             -polaroid -profile -quality -quantize -quiet \
  6989.             -red-primary -regard-warnings -repage -resize \
  6990.             -respect-parenthesis -rotate -sampling-factor -scenes \
  6991.             -seed -set -shadow -size -strip -stroke -texture \
  6992.             -thumbnail -tile -title -transform -transparent \
  6993.             -transparent-color -treedepth -trim -type -units \
  6994.             -verbose -version -virtual-pixel \
  6995.             -white-point' -- $cur ) )
  6996.     elif [[ "$cur" == +* ]]; then
  6997.         COMPREPLY=( $( compgen -W '+adjoin +compress +debug +dither \
  6998.             +endian +gamma +label +matte +page' -- $cur ) )
  6999.     else
  7000.         _filedir
  7001.     fi
  7002. }
  7003. complete -F _montage $filenames montage
  7004.  
  7005. _composite()
  7006. {
  7007.     local cur
  7008.  
  7009.     COMPREPLY=()
  7010.     cur=`_get_cword`
  7011.  
  7012.     _ImageMagick
  7013.  
  7014.     if [[ "$cur" == -* ]]; then
  7015.         COMPREPLY=( $( compgen -W '-affine -alpha -authenticate \
  7016.             -blend -blue-primary -border -bordercolor -channel \
  7017.             -colors -colorspace -comment -compose -compress \
  7018.             -debug -decipher -define -density -depth -displace \
  7019.             -display -dispose -dissolve -dither -encipher \
  7020.             -encoding -endian -extract -filter -font -format \
  7021.             -geometry -gravity -green-primary -help -identify \
  7022.             -interlace -interpolate -label -limit -list -log \
  7023.             -monitor -monochrome -negate -page -profile -quality \
  7024.             -quantize -quiet -red-primary -regard-warnings \
  7025.             -repage -resize -respect-parenthesis -rotate \
  7026.             -sampling-factor -scene -seed -sharpen -shave -size \
  7027.             -stegano -stereo -strip -swap -thumbnail -tile \
  7028.             -transform -transparent-color -treedepth -type -units \
  7029.             -unsharp -verbose -version -virtual-pixel -watermark \
  7030.             -white-point -write' -- $cur ) )
  7031.     elif [[ "$cur" == +* ]]; then
  7032.         COMPREPLY=( $( compgen -W '+compress +debug +dither +endian +label \
  7033.             +matte +negate +page +write' -- $cur ) )
  7034.     else
  7035.         _filedir
  7036.     fi
  7037. }
  7038. complete -F _composite $filenames composite
  7039.  
  7040. _compare()
  7041. {
  7042.     local cur
  7043.  
  7044.     COMPREPLY=()
  7045.     cur=`_get_cword`
  7046.  
  7047.     _ImageMagick
  7048.  
  7049.     if [[ "$cur" == -* ]]; then
  7050.         COMPREPLY=( $( compgen -W '-alpha -authenticate -channel \
  7051.             -colorspace -compress -debug -decipher -define \
  7052.             -density -depth -encipher -extract -format -fuzz \
  7053.             -help -highlight-color -identify -interlace -limit \
  7054.             -list -log -metric -monitor -passphrase -profile \
  7055.             -quality -quantize -quiet -regard-warnings \
  7056.             -respect-parenthesis -sampling-factor -seed -set \
  7057.             -size -transparent-color -type -verbose -version \
  7058.             -virtual-pixel' -- $cur ) )
  7059.     elif [[ "$cur" == +* ]]; then
  7060.         COMPREPLY=( $( compgen -W '+debug' -- $cur ) )
  7061.     else
  7062.         _filedir
  7063.     fi
  7064. }
  7065. complete -F _compare $filenames compare
  7066.  
  7067. _conjure()
  7068. {
  7069.     local cur
  7070.  
  7071.     COMPREPLY=()
  7072.     cur=`_get_cword`
  7073.  
  7074.     _ImageMagick
  7075.  
  7076.     if [[ "$cur" == -* ]]; then
  7077.         COMPREPLY=( $( compgen -W '-debug -help -list -log -monitor \
  7078.             -quiet -regard-warnings -seed -verbose \
  7079.             -version' -- $cur ) )
  7080.     elif [[ "$cur" == +* ]]; then
  7081.         COMPREPLY=( $( compgen -W '+debug' -- $cur ) )
  7082.     else
  7083.         _filedir
  7084.     fi
  7085. }
  7086. complete -F _conjure $filenames conjure
  7087.  
  7088. _import()
  7089. {
  7090.     local cur
  7091.  
  7092.     COMPREPLY=()
  7093.     cur=`_get_cword`
  7094.  
  7095.     _ImageMagick
  7096.  
  7097.     if [[ "$cur" == -* ]]; then
  7098.         COMPREPLY=( $( compgen -W '-adjoin -annotate -border -channel \
  7099.             -colors -colorspace -comment -compress -crop -debug \
  7100.             -define -delay -density -depth -descend -display \
  7101.             -dispose -dither -encipher -encoding -endian -filter \
  7102.             -format -frame -geometry -gravity -help -identify \
  7103.             -interlace -interpolate -label -limit -list -log \
  7104.             -monitor -monochrome -negate -page -pause -pointsize \
  7105.             -quality -quantize -quiet -regard-warnings -repage \
  7106.             -resize -respect-parenthesis -rotate -sampling-factor \
  7107.             -scene -screen -seed -set -silent -snaps -strip \
  7108.             -thumbnail -transparent -transparent-color -treedepth \
  7109.             -trim -type -verbose -version -virtual-pixel \
  7110.             -window' -- $cur ) )
  7111.     elif [[ "$cur" == +* ]]; then
  7112.         COMPREPLY=( $( compgen -W '+debug' -- $cur ) )
  7113.     else
  7114.         _filedir
  7115.     fi
  7116. }
  7117. complete -F _import $filenames import
  7118.  
  7119. _stream()
  7120. {
  7121.     local cur
  7122.  
  7123.     COMPREPLY=()
  7124.     cur=`_get_cword`
  7125.  
  7126.     _ImageMagick
  7127.  
  7128.     if [[ "$cur" == -* ]]; then
  7129.         COMPREPLY=( $( compgen -W '-authenticate -channel -colorspace \
  7130.             -compress -debug -define -density -depth -extract \ 
  7131.             -help -identify -interlace -interpolate -limit -list \
  7132.             -log -map -monitor -quantize -quiet -regard-warnings \
  7133.             -respect-parenthesis -sampling-factor -seed -set \
  7134.             -size -storage-type -transparent-color -verbose \
  7135.             -version -virtual-pixel' -- $cur ) )
  7136.     elif [[ "$cur" == +* ]]; then
  7137.         COMPREPLY=( $( compgen -W '+debug' -- $cur ) )
  7138.     else
  7139.         _filedir
  7140.     fi
  7141. }
  7142. complete -F _stream $filenames stream
  7143. }
  7144.  
  7145. # dd(1) completion
  7146. #
  7147. have dd &&
  7148. _dd()
  7149. {
  7150.      local cur
  7151.  
  7152.      COMPREPLY=()
  7153.      cur=`_get_cword`
  7154.  
  7155.      case "$cur" in
  7156.      if=*|of=*)
  7157.          cur=${cur#*=}
  7158.          _filedir
  7159.          return 0
  7160.          ;;
  7161.      conv=*)
  7162.          cur=${cur#*=}
  7163.          COMPREPLY=( $( compgen -W 'ascii ebcdic ibm block unblock \
  7164.                 lcase notrunc ucase swab noerror sync' \
  7165.                 -- $cur ) )
  7166.          return 0
  7167.          ;;
  7168.      esac
  7169.  
  7170.      _expand || return 0
  7171.  
  7172.      COMPREPLY=( $( compgen -W '--help --version' -- $cur ) \
  7173.              $( compgen -W 'bs cbs conv count ibs if obs of seek skip'\
  7174.                 -S '=' -- $cur ) )
  7175. } &&
  7176. complete -F _dd $nospace $filenames dd
  7177.  
  7178. # CUPS cancel(1) completion
  7179. #
  7180. have cancel &&
  7181. _cancel()
  7182. {
  7183.     local cur
  7184.  
  7185.     COMPREPLY=()
  7186.     cur=`_get_cword`
  7187.  
  7188.     COMPREPLY=( $( lpstat | cut -d' ' -f1 | grep "^$cur" ) )
  7189. } &&
  7190. complete -F _cancel $filenames cancel
  7191.  
  7192. # aspell(1) completion
  7193. #
  7194. have aspell && {
  7195. _aspell_dictionary()
  7196. {
  7197.     local datadir
  7198.     datadir=/usr/lib/aspell
  7199.     COMPREPLY=( $( command ls $datadir/*.@(multi|alias) ) )
  7200.     COMPREPLY=( ${COMPREPLY[@]%.@(multi|alias)} )
  7201.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]#$datadir/}' -- $cur ) )
  7202. }
  7203.  
  7204. _aspell()
  7205. {
  7206.     local cur prev
  7207.  
  7208.     COMPREPLY=()
  7209.     cur=`_get_cword`
  7210.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7211.  
  7212.     # --name value style option
  7213.     case "$prev" in
  7214.         @(-c|-p|check))
  7215.             _filedir
  7216.             return 0
  7217.             ;;
  7218.         @(dump|create|merge))
  7219.             COMPREPLY=( $( compgen -W 'master personal repl' -- $cur ) )
  7220.             return 0
  7221.             ;;
  7222.         -d)
  7223.             _aspell_dictionary
  7224.             return 0
  7225.             ;;
  7226.     esac
  7227.  
  7228.     # --name=value style option
  7229.     if [[ "$cur" == *=* ]]; then
  7230.         prev=${cur/=*/}
  7231.         cur=${cur/*=/}
  7232.         case "$prev" in
  7233.             --@(conf|personal|repl|per-conf))
  7234.                 _filedir
  7235.                 return 0
  7236.                 ;;
  7237.             --@(conf-dir|data-dir|dict-dir|home-dir|local-data-dir|prefix))
  7238.                 _filedir -d
  7239.                 return 0
  7240.                 ;;
  7241.             --master)
  7242.                 _aspell_dictionary
  7243.                 return 0
  7244.                 ;;
  7245.             --mode)
  7246.                 COMPREPLY=( $( compgen -W 'none url email sgml tex' -- $cur ) )
  7247.                 return 0
  7248.                 ;;
  7249.             --sug-mode)
  7250.                 COMPREPLY=( $( compgen -W 'ultra fast normal bad-speller' -- $cur ) )
  7251.                 return 0
  7252.                 ;;
  7253.             --keymapping)
  7254.                 COMPREPLY=( $( compgen -W 'aspell ispell' -- $cur ) )
  7255.                 return 0
  7256.                 ;;
  7257.         esac
  7258.     fi
  7259.  
  7260.     if [[ "$cur" == -* ]]; then
  7261.         COMPREPLY=( $( compgen -W '--conf= --conf-dir= --data-dir= --dict-dir= \
  7262.             --encoding= --add-filter= --rem-filter= --mode= -e \
  7263.             -H -t --add-extra-dicts= --rem-extra-dicts= \
  7264.             --home-dir= -W --ignore= --ignore-accents \
  7265.             --dont-ignore-accents --ignore-case --dont-ignore-case \
  7266.             --ignore-repl --dont-ignore-repl --jargon= --keyboard= \
  7267.             --lang= --language-tag= --local-data-dir= -d --master= \
  7268.             --module= --add-module-search-order= \
  7269.             --rem-module-search-order= --per-conf= -p --personal= \
  7270.             --prefix= --repl= -C -B --run-together --dont-run-together \
  7271.             --run-together-limit= --run-together-min= --save-repl \
  7272.             --dont-save-repl --set-prefix --dont-set-prefix --size= \
  7273.             --spelling= --strip-accents --dont-strip-accents \
  7274.             --sug-mode= --add-word-list-path= --rem-word-list-path= \
  7275.             -b -x --backup -b|-x --dont-backup --reverse --dont-reverse \
  7276.             --time --dont-time --keymapping= --add-email-quote= \
  7277.             --rem-email-quote= --email-margin= --add-tex-command= \
  7278.             --rem-tex-command= --tex-check-comments \
  7279.             --dont-tex-check-comments --add-tex-extension= \
  7280.             --rem-tex-extension= --add-sgml-check= --rem-sgml-check= \
  7281.             --add-sgml-extension= --rem-sgml-extension=' -- $cur ) )
  7282.     else
  7283.         COMPREPLY=( $( compgen -W '-? help -c check -a pipe -l list \
  7284.             config config soundslike filter -v version dump \
  7285.             create merge' -- $cur ) )
  7286.     fi
  7287.  
  7288. }
  7289. complete -F _aspell $filenames aspell
  7290. }
  7291.  
  7292. # xmms(1) completion
  7293. #
  7294. have xmms &&
  7295. _xmms()
  7296. {
  7297.     local cur
  7298.  
  7299.     COMPREPLY=()
  7300.     cur=`_get_cword`
  7301.  
  7302.     if [[ "$cur" == -* ]]; then
  7303.         COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \
  7304.             -u --pause -s --stop -t --play-pause -f --fwd -e \
  7305.             --enqueue -m --show-main-window -i --sm-client-id \
  7306.             -v --version' -- $cur ) )
  7307.     else
  7308.         _filedir '@(mp[23]|MP[23]|ogg|OGG|wav|WAV|pls|m3u|xm|mod|s[3t]m|it|mtm|ult|flac)'
  7309.  
  7310.     fi
  7311.  
  7312. } &&
  7313. complete -F _xmms $filenames xmms
  7314.  
  7315. # info(1) completion
  7316. #
  7317. have info &&
  7318. _info()
  7319. {
  7320.     local cur infopath UNAME
  7321.  
  7322.     COMPREPLY=()
  7323.     cur=`_get_cword`
  7324.  
  7325.     _expand || return 0
  7326.  
  7327.     # default completion if parameter contains /
  7328.     if [[ "$cur" == */* ]]; then
  7329.         _filedir
  7330.         return 0
  7331.     fi
  7332.  
  7333.     infopath='/usr/share/info'
  7334.  
  7335.     if [ "${INFOPATH: -1:1}" == ':' ]; then
  7336.         infopath=${INFOPATH}${infopath}
  7337.     elif [ ${INFOPATH:+set} ]; then
  7338.         infopath=$INFOPATH
  7339.     fi
  7340.  
  7341.     infopath=$infopath:
  7342.     if [ -n "$cur" ]; then
  7343.         infopath="${infopath//://$cur* }"
  7344.     else
  7345.         infopath="${infopath//:// }"
  7346.     fi
  7347.  
  7348.     # redirect stderr for when path doesn't exist
  7349.     COMPREPLY=( $( eval command ls "$infopath" 2>/dev/null ) )
  7350.     # weed out directory path names and paths to info pages
  7351.     COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
  7352.     # weed out info dir file
  7353.     for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
  7354.         if [ "${COMPREPLY[$i]}" == 'dir' ]; then
  7355.             unset COMPREPLY[$i];
  7356.         fi;
  7357.     done
  7358.     # strip suffix from info pages
  7359.     COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
  7360.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
  7361.  
  7362.     return 0
  7363. } &&
  7364. complete -F _info $filenames info
  7365.  
  7366. # dhclient(1) completion
  7367. #
  7368. have dhclient && _dhclient()
  7369. {
  7370.     local cur prev
  7371.  
  7372.     COMPREPLY=()
  7373.     cur=`_get_cword`
  7374.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7375.  
  7376.     case "$prev" in
  7377.         -@(cf|lf|pf|sf))
  7378.             _filedir
  7379.             return 0
  7380.             ;;
  7381.         -s)
  7382.             _known_hosts
  7383.             return 0
  7384.             ;;
  7385.     esac
  7386.  
  7387.     if [[ "$cur" == -* ]]; then
  7388.         COMPREPLY=( $( compgen -W '-p -d -q -1 -r -lf -pf \
  7389.             -cf -sf -s -g -n -nw -w' -- $cur ) )
  7390.     else
  7391.         _available_interfaces
  7392.     fi
  7393. } &&
  7394. complete -F _dhclient dhclient
  7395.  
  7396. # lvm(8) completion
  7397. #
  7398. have lvm && {
  7399. _volumegroups()
  7400. {
  7401.     COMPREPLY=( $(compgen -W "$( vgscan 2>/dev/null | \
  7402.         sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p' )" -- $cur ) )
  7403. }
  7404.  
  7405. _physicalvolumes()
  7406. {
  7407.     COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
  7408.         sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p' )" -- $cur ) )
  7409. }
  7410.  
  7411. _logicalvolumes()
  7412. {
  7413.     COMPREPLY=( $(compgen -W "$( lvscan 2>/dev/null | \
  7414.         sed -n -e "s|^.*'\(.*\)'.*$|\1|p" )" -- $cur ) )
  7415. }
  7416.  
  7417. _units()
  7418. {
  7419.     COMPREPLY=( $( compgen -W 'h s b k m g t H K M G T' -- $cur ) )
  7420. }
  7421.  
  7422. _sizes()
  7423. {
  7424.     COMPREPLY=( $( compgen -W 'k K m M g G t T' -- $cur ) )
  7425. }
  7426.  
  7427. _args()
  7428. {
  7429.     args=0
  7430.     if [[ "${COMP_WORDS[0]}" == lvm ]]; then
  7431.         offset=2
  7432.     else
  7433.         offset=1
  7434.     fi
  7435.     for (( i=$offset; i < COMP_CWORD; i++ )); do
  7436.         if [[ "${COMP_WORDS[i]}" != -* ]]; then
  7437.             args=$(($args + 1))
  7438.         fi
  7439.     done
  7440. }
  7441.  
  7442. _lvmdiskscan()
  7443. {
  7444.     local cur
  7445.  
  7446.     COMPREPLY=()
  7447.     cur=`_get_cword`
  7448.  
  7449.     if [[ "$cur" == -* ]]; then
  7450.         COMPREPLY=( $( compgen -W '-d --debug -h -? --help -l \
  7451.             --lvmpartition -v --verbose --version' -- $cur ) )
  7452.     fi
  7453. }
  7454. complete -F _lvmdiskscan lvmdiskscan
  7455.  
  7456. _pvscan()
  7457. {
  7458.     local cur
  7459.  
  7460.     COMPREPLY=()
  7461.     cur=`_get_cword`
  7462.  
  7463.     if [[ "$cur" == -* ]]; then
  7464.         COMPREPLY=( $( compgen -W '-d --debug -e \
  7465.             --exported -n --novolumegroup -h -? \
  7466.             --help --ignorelockingfailure -P \
  7467.             --partial -s --short -u --uuid -v \
  7468.             --verbose --version' -- $cur ) )
  7469.     fi
  7470. }
  7471. complete -F _pvscan pvscan
  7472.  
  7473. _pvs()
  7474. {
  7475.     local cur prev
  7476.  
  7477.     COMPREPLY=()
  7478.     cur=`_get_cword`
  7479.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7480.  
  7481.     case "$prev" in
  7482.         -@(o|O|-options|-sort))
  7483.             COMPREPLY=( $( compgen -W 'pv_fmt pv_uuid \
  7484.                 pv_size pv_free pv_used pv_name \
  7485.                 pv_attr pv_pe_count \
  7486.                 pv_pe_alloc_count' -- $cur ) )
  7487.             return 0
  7488.             ;;
  7489.         --units)
  7490.             _units
  7491.             return 0
  7492.             ;;
  7493.     esac
  7494.  
  7495.     if [[ "$cur" == -* ]]; then
  7496.         COMPREPLY=( $( compgen -W '--aligned -a --all -d --debug \
  7497.             -h -? --help --ignorelockingfailure --noheadings \
  7498.             --nosuffix -o --options -O --sort \
  7499.             --separator --unbuffered --units \
  7500.             -v --verbose --version' -- $cur ) )
  7501.     else
  7502.         _physicalvolumes
  7503.     fi
  7504. }
  7505. complete -F _pvs pvs
  7506.  
  7507. _pvdisplay()
  7508. {
  7509.     local cur prev
  7510.  
  7511.     COMPREPLY=()
  7512.     cur=`_get_cword`
  7513.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7514.  
  7515.     case "$prev" in
  7516.         --units)
  7517.             _units
  7518.             return 0
  7519.             ;;
  7520.     esac
  7521.  
  7522.     if [[ "$cur" == -* ]]; then
  7523.         COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
  7524.             -v --verbose -d --debug -h --help --version' -- $cur ) )
  7525.     else
  7526.         _physicalvolumes
  7527.     fi
  7528. }
  7529. complete -F _pvdisplay pvdisplay
  7530.  
  7531. _pvchange()
  7532. {
  7533.     local cur prev
  7534.  
  7535.     COMPREPLY=()
  7536.     cur=`_get_cword`
  7537.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7538.  
  7539.     case "$prev" in
  7540.         -@(A|x|-autobackup|--allocatable))
  7541.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7542.             return 0
  7543.             ;;
  7544.     esac
  7545.  
  7546.     if [[ "$cur" == -* ]]; then
  7547.         COMPREPLY=( $( compgen -W '-a --all -A --autobackup \
  7548.             -d --debug -h --help -t --test -u --uuid -x \
  7549.             --allocatable -v --verbose --addtag --deltag \
  7550.             --version' -- $cur ) )
  7551.     else
  7552.         _physicalvolumes
  7553.     fi
  7554. }
  7555. complete -F _pvchange pvchange
  7556.  
  7557. _pvcreate()
  7558. {
  7559.     local cur prev
  7560.  
  7561.     COMPREPLY=()
  7562.     cur=`_get_cword`
  7563.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7564.  
  7565.     case "$prev" in
  7566.         --restorefile)
  7567.             _filedir
  7568.             return 0
  7569.             ;;
  7570.         -@(M|-metadatatype))
  7571.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7572.             return 0
  7573.             ;;
  7574.         --metadatacopies)
  7575.             COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) )
  7576.             return 0
  7577.             ;;
  7578.         --@(metadatasize|setphysicalvolumesize))
  7579.             _sizes
  7580.             return 0
  7581.             ;;
  7582.     esac
  7583.  
  7584.     if [[ "$cur" == -* ]]; then
  7585.         COMPREPLY=( $( compgen -W '--restorefile -d --debug -f \
  7586.             --force -h -? --help --labelsector -M --metadatatype \
  7587.             --metadatacopies --metadatasize \
  7588.             --setphysicalvolumesize -t --test -u --uuid uuid -v \
  7589.             --verbose -y --yes --version' -- $cur ) )
  7590.     else
  7591.         _physicalvolumes
  7592.     fi
  7593. }
  7594. complete -F _pvcreate pvcreate
  7595.  
  7596. _pvmove()
  7597. {
  7598.     local cur prev
  7599.  
  7600.     COMPREPLY=()
  7601.     cur=`_get_cword`
  7602.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7603.  
  7604.     case "$prev" in
  7605.         -@(A|-autobackup))
  7606.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7607.             return 0
  7608.             ;;
  7609.         -@(n|-name))
  7610.             _logicalvolumes
  7611.             return 0
  7612.     esac
  7613.  
  7614.     if [[ "$cur" == -* ]]; then
  7615.         COMPREPLY=( $( compgen -W '--abort -A --autobackup \
  7616.             -b --background -d --debug -f --force -h -? \
  7617.             --help -i --interval -t --test -v --verbose \
  7618.             --version -n --name' -- $cur ) )
  7619.     else
  7620.         _physicalvolumes
  7621.     fi
  7622. }
  7623. complete -F _pvmove pvmove
  7624.  
  7625. _pvremove()
  7626. {
  7627.     local cur
  7628.  
  7629.     COMPREPLY=()
  7630.     cur=`_get_cword`
  7631.  
  7632.     if [[ "$cur" == -* ]]; then
  7633.         COMPREPLY=( $( compgen -W '-d --debug -f --force -h -? \
  7634.             --help -y --yes -t --test -v --verbose \
  7635.             --version' -- $cur ) )
  7636.     else
  7637.         _physicalvolumes
  7638.     fi
  7639. }
  7640. complete -F _pvremove pvremove
  7641.  
  7642. _vgscan()
  7643. {
  7644.     local cur
  7645.  
  7646.     COMPREPLY=()
  7647.     cur=`_get_cword`
  7648.  
  7649.     if [[ "$cur" == -* ]]; then
  7650.         COMPREPLY=( $( compgen -W '-d --debug -h --help \
  7651.             --ignorelockingfailure --mknodes -P \
  7652.             --partial -v --verbose --version' -- $cur ) )
  7653.     fi
  7654. }
  7655. complete -F _vgscan vgscan
  7656.  
  7657. _vgs()
  7658. {
  7659.     local cur prev
  7660.  
  7661.     COMPREPLY=()
  7662.     cur=`_get_cword`
  7663.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7664.  
  7665.     case "$prev" in
  7666.         -@(o|O|-options|-sort))
  7667.             COMPREPLY=( $( compgen -W 'vg_fmt vg_uuid vg_name \
  7668.                 vg_attr vg_size vg_free vg_sysid \
  7669.                 vg_extent_size vg_extent_count vg_free_count \
  7670.                 max_lv max_pv pv_count lv_count snap_count \
  7671.                 vg_seqno' -- $cur ) )
  7672.             return 0
  7673.             ;;
  7674.         --units)
  7675.             _units
  7676.             return 0
  7677.             ;;
  7678.     esac
  7679.  
  7680.     if [[ "$cur" == -* ]]; then
  7681.         COMPREPLY=( $( compgen -W '--aligned -d --debug \
  7682.             -h --help --ignorelockingfailure --noheadings \
  7683.             --nosuffix -o --options -O --sort -P --partial \
  7684.             --separator --unbuffered --units \
  7685.             -v --verbose --version' -- $cur ) )
  7686.     else
  7687.         _volumegroups
  7688.     fi
  7689. }
  7690. complete -F _vgs vgs
  7691.  
  7692. _vgdisplay()
  7693. {
  7694.     local cur prev
  7695.  
  7696.     COMPREPLY=()
  7697.     cur=`_get_cword`
  7698.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7699.  
  7700.     case "$prev" in
  7701.         --units)
  7702.             _units
  7703.             return 0
  7704.             ;;
  7705.     esac
  7706.  
  7707.     if [[ "$cur" == -* ]]; then
  7708.         COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
  7709.             -P --partial -A --activevolumegroups -v --verbose \
  7710.             -d --debug -h --help --version' -- $cur ) )
  7711.     else
  7712.         _volumegroups
  7713.     fi
  7714. }
  7715. complete -F _vgdisplay vgdisplay
  7716.  
  7717. _vgchange()
  7718. {
  7719.     local cur prev
  7720.  
  7721.     COMPREPLY=()
  7722.     cur=`_get_cword`
  7723.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7724.  
  7725.     case "$prev" in
  7726.         -@(a|A|x|-available|-autobackup|-resizeable))
  7727.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7728.             return 0
  7729.             ;;
  7730.     esac
  7731.  
  7732.     if [[ "$cur" == -* ]]; then
  7733.         COMPREPLY=( $( compgen -W '-A --autobackup --alloc -P \
  7734.             --partial -d --debug -h --help --ignorelockingfailure \
  7735.             -t --test -u --uuid -v --verbose --version -a \
  7736.             --available -x --resizeable -l --logicalvolume \
  7737.             --addtag --deltag' -- $cur ) )
  7738.     else
  7739.         _volumegroups
  7740.     fi
  7741. }
  7742. complete -F _vgchange vgchange
  7743.  
  7744. _vgcreate()
  7745. {
  7746.     local cur prev
  7747.  
  7748.     COMPREPLY=()
  7749.     cur=`_get_cword`
  7750.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7751.  
  7752.     case "$prev" in
  7753.         -@(A|-autobackup))
  7754.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7755.             return 0
  7756.             ;;
  7757.         -@(M|-metadatatype))
  7758.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7759.             return 0
  7760.             ;;
  7761.         -@(s|-physicalextentsize))
  7762.             _sizes
  7763.             return 0
  7764.             ;;
  7765.     esac
  7766.  
  7767.     if [[ "$cur" == -* ]]; then
  7768.         COMPREPLY=( $( compgen -W '-A --autobackup --addtag \
  7769.             --alloc -d --debug -h --help -l --maxlogicalvolumes \
  7770.             -M --metadatatype -p --maxphysicalvolumes -s \
  7771.             --physicalextentsize -t --test -v --verbose \
  7772.             --version' -- $cur ) )
  7773.     else
  7774.         _args
  7775.         if [ $args -eq 0 ]; then
  7776.             _volumegroups
  7777.         else
  7778.             _physicalvolumes
  7779.         fi
  7780.     fi
  7781. }
  7782. complete -F _vgcreate vgcreate
  7783.  
  7784. _vgremove()
  7785. {
  7786.     local cur
  7787.  
  7788.     COMPREPLY=()
  7789.     cur=`_get_cword`
  7790.  
  7791.     if [[ "$cur" == -* ]]; then
  7792.         COMPREPLY=( $( compgen -W '-d --debug -h --help -t --test \
  7793.         -v --verbose --version' -- $cur ) )
  7794.     else
  7795.         _volumegroups
  7796.     fi
  7797. }
  7798. complete -F _vgremove vgremove
  7799.  
  7800. _vgrename()
  7801. {
  7802.     local cur prev
  7803.  
  7804.     COMPREPLY=()
  7805.     cur=`_get_cword`
  7806.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7807.  
  7808.     case "$prev" in
  7809.         -@(A|-autobackup))
  7810.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7811.             return 0
  7812.             ;;
  7813.     esac
  7814.  
  7815.     if [[ "$cur" == -* ]]; then
  7816.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
  7817.             -? --help -t --test -v --verbose --version' -- $cur ) )
  7818.     else
  7819.         _volumegroups
  7820.     fi
  7821. }
  7822. complete -F _vgrename vgrename
  7823.  
  7824. _vgreduce()
  7825. {
  7826.     local cur prev
  7827.  
  7828.     COMPREPLY=()
  7829.     cur=`_get_cword`
  7830.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7831.  
  7832.     case "$prev" in
  7833.         -@(A|-autobackup))
  7834.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7835.             return 0
  7836.             ;;
  7837.     esac
  7838.  
  7839.     if [[ "$cur" == -* ]]; then
  7840.         COMPREPLY=( $( compgen -W '-a --all -A --autobackup -d \
  7841.             --debug -h --help --removemissing -t --test -v \
  7842.             --verbose --version' -- $cur ) )
  7843.  
  7844.     else
  7845.         _args
  7846.         if [ $args -eq 0 ]; then
  7847.             _volumegroups
  7848.         else
  7849.             _physicalvolumes
  7850.         fi
  7851.     fi
  7852. }
  7853. complete -F _vgreduce vgreduce
  7854.  
  7855. _vgextend()
  7856. {
  7857.     local cur prev
  7858.  
  7859.     COMPREPLY=()
  7860.     cur=`_get_cword`
  7861.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7862.  
  7863.     case "$prev" in
  7864.         -@(A|-autobackup))
  7865.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  7866.             return 0
  7867.             ;;
  7868.         -@(L|-size))
  7869.             _sizes
  7870.             return 0
  7871.             ;;
  7872.     esac
  7873.  
  7874.     if [[ "$cur" == -* ]]; then
  7875.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
  7876.             -? --help -t --test -v --verbose --version' -- $cur ) )
  7877.     else
  7878.         _args
  7879.         if [ $args -eq 0 ]; then
  7880.             _volumegroups
  7881.         else
  7882.             _physicalvolumes
  7883.         fi
  7884.     fi
  7885. }
  7886. complete -F _vgextend vgextend
  7887.  
  7888. _vgport()
  7889. {
  7890.     local cur prev
  7891.  
  7892.     COMPREPLY=()
  7893.     cur=`_get_cword`
  7894.  
  7895.     if [[ "$cur" == -* ]]; then
  7896.         COMPREPLY=( $( compgen -W '-a --all -d --debug -h \
  7897.             -? --help -v --verbose --version' -- $cur ) )
  7898.     else
  7899.         _volumegroups
  7900.     fi
  7901. }
  7902. complete -F _vgport vgimport vgexport
  7903.  
  7904. _vgck()
  7905. {
  7906.     local cur prev
  7907.  
  7908.     COMPREPLY=()
  7909.     cur=`_get_cword`
  7910.  
  7911.     if [[ "$cur" == -* ]]; then
  7912.         COMPREPLY=( $( compgen -W '-d --debug -h \
  7913.             -? --help -v --verbose --version' -- $cur ) )
  7914.     else
  7915.         _volumegroups
  7916.     fi
  7917. }
  7918. complete -F _vgck vgck
  7919.  
  7920. _vgconvert()
  7921. {
  7922.     local cur prev
  7923.  
  7924.     COMPREPLY=()
  7925.     cur=`_get_cword`
  7926.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7927.  
  7928.     case "$prev" in
  7929.         -@(M|-metadatatype))
  7930.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7931.             return 0
  7932.             ;;
  7933.         --metadatacopies)
  7934.             COMPREPLY=( $( compgen -W '0 1 2' -- $cur ) )
  7935.             return 0
  7936.             ;;
  7937.         --metadatasize)
  7938.             _sizes
  7939.             return 0
  7940.             ;;
  7941.     esac
  7942.  
  7943.     if [[ "$cur" == -* ]]; then
  7944.         COMPREPLY=( $( compgen -W '-d --debug -h --help --labelsector \
  7945.             -M --metadatatype --metadatacopies --metadatasize \
  7946.             -t --test -v --verbose --version' -- $cur ) )
  7947.     else
  7948.         _volumegroups
  7949.     fi
  7950. }
  7951. complete -F _vgconvert vgconvert
  7952.  
  7953. _vgcfgbackup()
  7954. {
  7955.     local cur prev
  7956.  
  7957.     COMPREPLY=()
  7958.     cur=`_get_cword`
  7959.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7960.  
  7961.     case "$prev" in
  7962.         -@(f|-file))
  7963.             _filedir
  7964.             return 0
  7965.             ;;
  7966.     esac
  7967.  
  7968.     if [[ "$cur" == -* ]]; then
  7969.         COMPREPLY=( $( compgen -W '-d --debug -f --file -h --help \
  7970.             --ignorelockingfailure -P --partial -v --verbose \
  7971.             --version' -- $cur ) )
  7972.     else
  7973.         _volumegroups
  7974.     fi
  7975. }
  7976. complete -F _vgcfgbackup vgcfgbackup
  7977.  
  7978. _vgcfgrestore()
  7979. {
  7980.     local cur prev
  7981.  
  7982.     COMPREPLY=()
  7983.     cur=`_get_cword`
  7984.     prev=${COMP_WORDS[COMP_CWORD-1]}
  7985.  
  7986.     case "$prev" in
  7987.         -@(f|-file))
  7988.             _filedir
  7989.             return 0
  7990.             ;;
  7991.         -@(M|-metadatatype))
  7992.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  7993.             return 0
  7994.             ;;
  7995.         -@(n|-name))
  7996.             _volumegroups
  7997.             return 0
  7998.             ;;
  7999.     esac
  8000.  
  8001.     if [[ "$cur" == -* ]]; then
  8002.         COMPREPLY=( $( compgen -W '-d --debug -f --file -l --list \
  8003.             -h --help -M --Metadatatype -n --name -t --test \
  8004.             -v --verbose --version' -- $cur ) )
  8005.     else
  8006.         _volumegroups
  8007.     fi
  8008. }
  8009. complete -F _vgcfgrestore vgcfgrestore
  8010.  
  8011. _vgmerge()
  8012. {
  8013.     local cur prev
  8014.  
  8015.     COMPREPLY=()
  8016.     cur=`_get_cword`
  8017.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8018.  
  8019.     case "$prev" in
  8020.         -@(A|-autobackup))
  8021.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8022.             return 0
  8023.             ;;
  8024.     esac
  8025.  
  8026.     if [[ "$cur" == -* ]]; then
  8027.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \
  8028.             -h --help -l --list -t --test -v --verbose \
  8029.             --version' -- $cur ) )
  8030.     else
  8031.         _volumegroups
  8032.     fi
  8033. }
  8034. complete -F _vgmerge vgmerge
  8035.  
  8036. _vgsplit()
  8037. {
  8038.     local cur prev
  8039.  
  8040.     COMPREPLY=()
  8041.     cur=`_get_cword`
  8042.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8043.  
  8044.     case "$prev" in
  8045.         -@(A|-autobackup))
  8046.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8047.             return 0
  8048.             ;;
  8049.         -@(M|-metadatatype))
  8050.             COMPREPLY=( $( compgen -W '1 2' -- $cur ) )
  8051.             return 0
  8052.             ;;
  8053.     esac
  8054.  
  8055.     if [[ "$cur" == -* ]]; then
  8056.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug \
  8057.             -h --help -l --list -M --metadatatype -t --test \
  8058.             -v --verbose --version' -- $cur ) )
  8059.     else
  8060.         _args
  8061.         if [ $args -eq 0 -o $args -eq 1 ]; then
  8062.             _volumegroups
  8063.         else
  8064.             _physicalvolumes
  8065.         fi
  8066.     fi
  8067. }
  8068. complete -F _vgsplit vgsplit
  8069.  
  8070. _vgmknodes()
  8071. {
  8072.     local cur
  8073.  
  8074.     COMPREPLY=()
  8075.     cur=`_get_cword`
  8076.  
  8077.     if [[ "$cur" == -* ]]; then
  8078.         COMPREPLY=( $( compgen -W '-d --debug -h --help -v --verbose \
  8079.             --version' -- $cur ) )
  8080.     else
  8081.         _volumegroups
  8082.     fi
  8083. }
  8084. complete -F _vgmknodes vgmknodes
  8085.  
  8086. _lvscan()
  8087. {
  8088.     local cur
  8089.  
  8090.     COMPREPLY=()
  8091.     cur=`_get_cword`
  8092.  
  8093.     if [[ "$cur" == -* ]]; then
  8094.         COMPREPLY=( $( compgen -W '-b --blockdevice -d --debug \
  8095.             -h -? --help --ignorelockingfailure -P \
  8096.             --partial -v --verbose --version' -- $cur ) )
  8097.     fi
  8098. }
  8099. complete -F _lvscan lvscan
  8100.  
  8101. _lvs()
  8102. {
  8103.     local cur prev
  8104.  
  8105.     COMPREPLY=()
  8106.     cur=`_get_cword`
  8107.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8108.  
  8109.     case "$prev" in
  8110.         -@(o|O|-options|-sort))
  8111.             COMPREPLY=( $( compgen -W 'lv_uuid lv_name \
  8112.                 lv_attr lv_minor lv_size seg_count \
  8113.                 origin snap_percent segtype stripes \
  8114.                 stripesize chunksize seg_start \
  8115.                 seg_size' -- $cur ) )
  8116.             return 0
  8117.             ;;
  8118.         --units)
  8119.             _units
  8120.             return 0
  8121.             ;;
  8122.     esac
  8123.  
  8124.     if [[ "$cur" == -* ]]; then
  8125.         COMPREPLY=( $( compgen -W '--aligned -d --debug \
  8126.             -h --help --ignorelockingfailure --noheadings \
  8127.             --nosuffix -o --options -O --sort -P --partial \
  8128.             --segments --separator --unbuffered --units \
  8129.             -v --verbose --version' -- $cur ) )
  8130.     else
  8131.         _logicalvolumes
  8132.     fi
  8133. }
  8134. complete -F _lvs lvs
  8135.  
  8136. _lvdisplay()
  8137. {
  8138.     local cur prev
  8139.  
  8140.     COMPREPLY=()
  8141.     cur=`_get_cword`
  8142.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8143.  
  8144.     case "$prev" in
  8145.         --units)
  8146.             _units
  8147.             return 0
  8148.             ;;
  8149.     esac
  8150.  
  8151.     if [[ "$cur" == -* ]]; then
  8152.         COMPREPLY=( $( compgen -W '-c --colon -C --columns --units \
  8153.             -P --partial -m --maps -v --verbose -d --debug -h \
  8154.             --help --version' -- $cur ) )
  8155.     else
  8156.         _logicalvolumes
  8157.     fi
  8158. }
  8159. complete -F _lvdisplay lvdisplay
  8160.  
  8161. _lvchange()
  8162. {
  8163.     local cur prev
  8164.  
  8165.     COMPREPLY=()
  8166.     cur=`_get_cword`
  8167.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8168.  
  8169.     case "$prev" in
  8170.         -@(a|A|C|M|-available|-autobackup|-continguous|-persistent))
  8171.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8172.             return 0
  8173.             ;;
  8174.         -@(p|-permission))
  8175.             COMPREPLY=( $( compgen -W 'r rw' -- $cur ) )
  8176.             return 0
  8177.             ;;
  8178.     esac
  8179.  
  8180.     if [[ "$cur" == -* ]]; then
  8181.         COMPREPLY=( $( compgen -W '-A --autobackup -a --available \
  8182.             --addtag --alloc -C --contiguous -d --debug --deltag \
  8183.             -f --force -h --help --ignorelockingfailure -M \
  8184.             --persistent --major major --minor minor -P --partial \
  8185.             -p --permission -r --readahead --refresh -t --test \
  8186.             -v --verbose --version' -- $cur ) )
  8187.     else
  8188.         _logicalvolumes
  8189.     fi
  8190. }
  8191. complete -F _lvchange lvchange
  8192.  
  8193. _lvcreate()
  8194. {
  8195.     local cur prev
  8196.  
  8197.     COMPREPLY=()
  8198.     cur=`_get_cword`
  8199.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8200.  
  8201.     case "$prev" in
  8202.         -@(A|C|M|Z|-autobackup|-continguous|-persistent|-zero))
  8203.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8204.             return 0
  8205.             ;;
  8206.         -@(L|-size))
  8207.             _sizes
  8208.             return 0
  8209.             ;;
  8210.         -@(p|-permission))
  8211.             COMPREPLY=( $( compgen -W 'r rw' -- $cur ) )
  8212.             return 0
  8213.             ;;
  8214.         -@(n|-name))
  8215.             _logicalvolumes
  8216.             return 0
  8217.             ;;
  8218.     esac
  8219.  
  8220.     if [[ "$cur" == -* ]]; then
  8221.         COMPREPLY=( $( compgen -W '-A --autobackup --addtag --alloc \
  8222.             -C --contiguous -d --debug -h -? --help -i --stripes \
  8223.             -I --stripesize -l --extents -L --size -M --persistent \
  8224.             --major --minor -n --name -p --permission -r \
  8225.             --readahead -t --test --type -v --verbose -Z --zero \
  8226.             --version' -- $cur ) )
  8227.     else
  8228.         _args
  8229.         if [ $args -eq 0 ]; then
  8230.             _volumegroups
  8231.         else
  8232.             _physicalvolumes
  8233.         fi
  8234.     fi
  8235. }
  8236. complete -F _lvcreate lvcreate
  8237.  
  8238. _lvremove()
  8239. {
  8240.     local cur prev
  8241.  
  8242.     COMPREPLY=()
  8243.     cur=`_get_cword`
  8244.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8245.  
  8246.     case "$prev" in
  8247.         -@(A|-autobackup))
  8248.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8249.             return 0
  8250.             ;;
  8251.     esac
  8252.  
  8253.     if [[ "$cur" == -* ]]; then
  8254.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -f \
  8255.             --force -h -?  --help -t --test -v --verbose \
  8256.             --version' -- $cur ) )
  8257.     else
  8258.         _logicalvolumes
  8259.     fi
  8260. }
  8261. complete -F _lvremove lvremove
  8262.  
  8263. _lvrename()
  8264. {
  8265.     local cur prev
  8266.  
  8267.     COMPREPLY=()
  8268.     cur=`_get_cword`
  8269.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8270.  
  8271.     case "$prev" in
  8272.         -@(A|-autobackup))
  8273.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8274.             return 0
  8275.             ;;
  8276.     esac
  8277.  
  8278.     if [[ "$cur" == -* ]]; then
  8279.         COMPREPLY=( $( compgen -W '-A --autobackup -d --debug -h \
  8280.             -? --help -t --test -v --verbose --version' -- $cur ) )
  8281.     else
  8282.         _logicalvolumes
  8283.     fi
  8284. }
  8285. complete -F _lvrename lvrename
  8286.  
  8287. _lvreduce()
  8288. {
  8289.     local cur prev
  8290.  
  8291.     COMPREPLY=()
  8292.     cur=`_get_cword`
  8293.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8294.  
  8295.     case "$prev" in
  8296.         -@(A|-autobackup))
  8297.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8298.             return 0
  8299.             ;;
  8300.         -@(L|-size))
  8301.             _sizes
  8302.             return 0
  8303.             ;;
  8304.     esac
  8305.  
  8306.     if [[ "$cur" == -* ]]; then
  8307.         COMPREPLY=( $( compgen -W '-A --autobackup -d \
  8308.             --debug -f --force -h --help -l --extents \
  8309.             -L --size -n --nofsck -r --resizefs -t --test \
  8310.             -v --verbose --version' -- $cur ) )
  8311.     else
  8312.         _logicalvolumes
  8313.     fi
  8314. }
  8315. complete -F _lvreduce lvreduce
  8316.  
  8317. _lvresize()
  8318. {
  8319.     local cur prev
  8320.  
  8321.     COMPREPLY=()
  8322.     cur=`_get_cword`
  8323.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8324.  
  8325.     case "$prev" in
  8326.         -@(A|-autobackup))
  8327.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8328.             return 0
  8329.             ;;
  8330.         -@(L|-size))
  8331.             _sizes
  8332.             return 0
  8333.             ;;
  8334.     esac
  8335.  
  8336.     if [[ "$cur" == -* ]]; then
  8337.         COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \
  8338.             --debug -h --help -i --stripes -I --stripesize \
  8339.             -l --extents -L --size -n --nofsck -r --resizefs \
  8340.             -t --test --type -v --verbose --version' -- $cur ) )
  8341.     else
  8342.         _args
  8343.         if [ $args -eq 0 ]; then
  8344.             _logicalvolumes
  8345.         else
  8346.             _physicalvolumes
  8347.         fi
  8348.     fi
  8349. }
  8350. complete -F _lvresize lvresize
  8351.  
  8352. _lvextend()
  8353. {
  8354.     local cur prev
  8355.  
  8356.     COMPREPLY=()
  8357.     cur=`_get_cword`
  8358.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8359.  
  8360.     case "$prev" in
  8361.         -@(A|-autobackup))
  8362.             COMPREPLY=( $( compgen -W 'y n' -- $cur ) )
  8363.             return 0
  8364.             ;;
  8365.         -@(L|-size))
  8366.             _sizes
  8367.             return 0
  8368.             ;;
  8369.     esac
  8370.  
  8371.     if [[ "$cur" == -* ]]; then
  8372.         COMPREPLY=( $( compgen -W '-A --autobackup --alloc -d \
  8373.             --debug -h --help -i --stripes -I --stripesize \
  8374.             -l --extents -L --size -n --nofsck -r --resizefs \
  8375.             -t --test --type -v --verbose --version' -- $cur ) )
  8376.     else
  8377.         _args
  8378.         if [ $args -eq 0 ]; then
  8379.             _logicalvolumes
  8380.         else
  8381.             _physicalvolumes
  8382.         fi
  8383.     fi
  8384. }
  8385. complete -F _lvextend lvextend
  8386.  
  8387. _lvm()
  8388. {
  8389.     local prev
  8390.  
  8391.     COMPREPLY=()
  8392.     cur=`_get_cword`
  8393.  
  8394.     if [ $COMP_CWORD -eq 1 ]; then
  8395.         COMPREPLY=( $( compgen -W 'dumpconfig help lvchange \
  8396.             lvcreate lvdisplay lvextend lvmchange \
  8397.             lvmdiskscan lvmsadc lvmsar lvreduce \
  8398.             lvremove lvrename lvresize lvs lvscan \
  8399.             pvchange pvcreate pvdata pvdisplay pvmove \
  8400.             pvremove pvresize pvs pvscan vgcfgbackup \
  8401.             vgcfgrestore vgchange vgck vgconvert \
  8402.             vgcreate vgdisplay vgexport vgextend \
  8403.             vgimport vgmerge vgmknodes vgreduce \
  8404.             vgremove vgrename vgs vgscan vgsplit \
  8405.             version' -- $cur ) )
  8406.     else
  8407.         case ${COMP_WORDS[1]} in
  8408.             pvchange)
  8409.                 _pvchange
  8410.                 ;;
  8411.             pvcreate)
  8412.                 _pvcreate
  8413.                 ;;
  8414.             pvdisplay)
  8415.                 _pvdisplay
  8416.                 ;;
  8417.             pvmove)
  8418.                 _pvmove
  8419.                 ;;
  8420.             pvremove)
  8421.                 _pvremove
  8422.                 ;;
  8423.             pvresize)
  8424.                 _pvresize
  8425.                 ;;
  8426.             pvs)
  8427.                 _pvs
  8428.                 ;;
  8429.             pvscan)
  8430.                 _pvscan
  8431.                 ;;
  8432.             vgcfgbackup)
  8433.                 _vgcfgbackup
  8434.                 ;;
  8435.             vgcfgrestore)
  8436.                 _vgcfgrestore
  8437.                 ;;
  8438.             vgchange)
  8439.                 _vgchange
  8440.                 ;;
  8441.             vgck)
  8442.                 _vgck
  8443.                 ;;
  8444.             vgconvert)
  8445.                 _vgconvert
  8446.                 ;;
  8447.             vgcreate)
  8448.                 _vgcreate
  8449.                 ;;
  8450.             vgdisplay)
  8451.                 _vgdisplay
  8452.                 ;;
  8453.             vgexport)
  8454.                 _vgexport
  8455.                 ;;
  8456.             vgextend)
  8457.                 _vgextend
  8458.                 ;;
  8459.             vgimport)
  8460.                 _vgimport
  8461.                 ;;
  8462.             vgmerge)
  8463.                 _vgmerge
  8464.                 ;;
  8465.             vgmknodes)
  8466.                 _vgmknodes
  8467.                 ;;
  8468.             vgreduce)
  8469.                 _vgreduce
  8470.                 ;;
  8471.             vgremove)
  8472.                 _vgremove
  8473.                 ;;
  8474.             vgrename)
  8475.                 _vgrename
  8476.                 ;;
  8477.             vgs)
  8478.                 _vgs
  8479.                 ;;
  8480.             vgscan)
  8481.                 _vgscan
  8482.                 ;;
  8483.             vgsplit)
  8484.                 _vgsplit
  8485.                 ;;
  8486.             lvchange)
  8487.                 _lvchange
  8488.                 ;;
  8489.             lvcreate)
  8490.                 _lvcreate
  8491.                 ;;
  8492.             lvdisplay)
  8493.                 _lvdisplay
  8494.                 ;;
  8495.             lvextend)
  8496.                 _lvextend
  8497.                 ;;
  8498.             lvreduce)
  8499.                 _lvreduce
  8500.                 ;;
  8501.             lvremove)
  8502.                 _lvremove
  8503.                 ;;
  8504.             lvrename)
  8505.                 _lvrename
  8506.                 ;;
  8507.             lvresize)
  8508.                 _lvresize
  8509.                 ;;
  8510.             lvs)
  8511.                 _lvs
  8512.                 ;;
  8513.             lvscan)
  8514.                 _lvscan
  8515.                 ;;
  8516.         esac
  8517.     fi
  8518. }
  8519. complete -F _lvm lvm
  8520. }
  8521.  
  8522. # mkinitrd(8) completion
  8523. #
  8524. have mkinitrd &&
  8525. _mkinitrd()
  8526. {
  8527.     local cur args
  8528.  
  8529.     COMPREPLY=()
  8530.     cur=`_get_cword`
  8531.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8532.  
  8533.     # --name value style option
  8534.     case "$prev" in
  8535.         --preload)
  8536.             _modules
  8537.             return 0
  8538.             ;;
  8539.     esac
  8540.  
  8541.     # --name=value style option
  8542.     if [[ "$cur" == *=* ]]; then
  8543.         prev=${cur/=*/}
  8544.         cur=${cur/*=/}
  8545.         case "$prev" in
  8546.             --@(with|builtin))
  8547.                 _modules
  8548.                 return 0
  8549.                 ;;
  8550.             --@(fstab|dsdt))
  8551.                 _filedir
  8552.                 return 0
  8553.                 ;;
  8554.             --tmpdir)
  8555.                 _filedir -d
  8556.                 return 0
  8557.                 ;;
  8558.         esac
  8559.     fi
  8560.  
  8561.  
  8562.     if [[ "$cur" == -* ]]; then
  8563.         COMPREPLY=( $( compgen -W '--version -v -f --preload \
  8564.             --with= --omit-scsi-modules --omit-raid-modules \
  8565.             --images-version --fstab= --nocompress --builtin= \
  8566.             --nopivot --noudev --allow-missing --tmpdir= \
  8567.             --initrdfs= --dsdt= --lvm-version= --froce-usb' \
  8568.             -- $cur ) )
  8569.     else
  8570.         _count_args
  8571.  
  8572.         case $args in
  8573.             1)
  8574.                 _filedir
  8575.                 ;;
  8576.             2)
  8577.                 COMPREPLY=( $( command ls /lib/modules | grep "^$cur" ) )
  8578.                 ;;
  8579.         esac
  8580.     fi
  8581.  
  8582. } &&
  8583. complete -F _mkinitrd mkinitrd
  8584.  
  8585. # pkgconfig(1) completion
  8586. #
  8587. have pkg-config &&
  8588. _pkg_config()
  8589. {
  8590.     local cur
  8591.  
  8592.     COMPREPLY=()
  8593.     cur=`_get_cword`
  8594.  
  8595.     if [[ "$cur" == -* ]]; then
  8596.         # return list of available options
  8597.         COMPREPLY=( $( compgen -W '-version --modversion \
  8598.               --atleast-pkgconfig-version= --libs --libs-only-l \
  8599.               --libs-only-other --libs-only-L --cflags \
  8600.               --cflags-only-I --cflags-only-other --variable= \
  8601.               --define-variable= --exists --uninstalled \
  8602.               --atleast-version= --exact-version= --max-version= \
  8603.               --list-all --debug --print-errors --silence-errors \
  8604.               --errors-to-stdout -? --help --usage' -- $cur))
  8605.     else
  8606.         COMPREPLY=( $( pkg-config --list-all 2>/dev/null | \
  8607.                     awk '{print $1}' | grep "^$cur" ) )
  8608.     fi
  8609. } &&
  8610. complete -F _pkg_config pkg-config
  8611.  
  8612.  
  8613. # cpio(1) completion
  8614. #
  8615. have cpio && {
  8616. _cpio_format()
  8617. {
  8618.     COMPREPLY=( $( compgen -W 'bin odc newc crc tar ustar hpbin hpodc' -- $cur ) )
  8619. }
  8620.  
  8621. _cpio()
  8622. {
  8623.     local cur
  8624.  
  8625.     COMPREPLY=()
  8626.     cur=`_get_cword`
  8627.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8628.  
  8629.     # --name value style option
  8630.     case $prev in
  8631.         -H)
  8632.             _cpio_format
  8633.             return 0
  8634.             ;;
  8635.         -@(E|F|I))
  8636.             _filedir
  8637.             return 0
  8638.             ;;
  8639.         -R)
  8640.             _usergroup
  8641.             return 0
  8642.             ;;
  8643.     esac
  8644.  
  8645.     # --name=value style option
  8646.     if [[ "$cur" == *=* ]]; then
  8647.         prev=${cur/=*/}
  8648.         cur=${cur/*=/}
  8649.         case $prev in
  8650.             --format)
  8651.                 _cpio_format
  8652.                 return 0
  8653.                 ;;
  8654.             --@(file|pattern-file))
  8655.                 _filedir
  8656.                 return 0
  8657.                 ;;
  8658.             --owner)
  8659.                 _usergroup
  8660.                 return 0
  8661.                 ;;
  8662.             --rsh-command)
  8663.                 COMPREPLY=( $( compgen -c -- $cur ) )
  8664.                 return 0
  8665.                 ;;
  8666.         esac
  8667.     fi
  8668.  
  8669.     if [ $COMP_CWORD -eq 1 ]; then
  8670.         COMPREPLY=( $( compgen -W '-o --create -i --extract -p --pass-through' -- $cur) )
  8671.     else
  8672.         case ${COMP_WORDS[1]} in
  8673.             -@(o|-create))
  8674.                 if [[ "$cur" == -* ]]; then
  8675.                     COMPREPLY=( $( compgen -W '-0 -a -c -v -A -B\
  8676.                         -L -V -C -H -M -O -F --file= --format=\
  8677.                         --message= --null --reset-access-time\
  8678.                         --verbose --dot --append --block-size=\
  8679.                         --dereference --io-size= --quiet\
  8680.                         --force-local --rsh-command= --help\
  8681.                         --version' -- $cur ) )
  8682.                 fi
  8683.                 ;;
  8684.             -@(i|-extract))
  8685.                 if [[ "$cur" == -* ]]; then
  8686.                     COMPREPLY=( $( compgen -W '-b -c -d -f -m -n -r\
  8687.                         -t -s -u -v -B -S -V -C -E -H -M -R -I\
  8688.                         -F --file= --make-directories\
  8689.                         --nonmatching\
  8690.                         --preserve-modification-time\
  8691.                         --numeric-uid-gid --rename -t --list\
  8692.                         --swap-bytes --swap --dot\
  8693.                         --unconditional --verbose --block-size=\
  8694.                         --swap-halfwords --io-size=\
  8695.                         --pattern-file= --format= --owner=\
  8696.                         --no-preserve-owner --message=\
  8697.                         --force-local --no-absolute-filenames\
  8698.                         --sparse --only-verify-crc --quiet\
  8699.                         --rsh-command= --help\
  8700.                         --version' -- $cur ) )
  8701.                 fi
  8702.                 ;;
  8703.             -@(p|-pass-through))
  8704.                 if [[ "$cur" == -* ]]; then
  8705.                     COMPREPLY=( $( compgen -W '-0 -a -d -l -m -u -v\
  8706.                         -L -V -R --null --reset-access-time\
  8707.                         --make-directories --link --quiet\
  8708.                         --preserve-modification-time\
  8709.                         --unconditional --verbose --dot\
  8710.                         --dereference --owner=\
  8711.                         --no-preserve-owner --sparse --help\
  8712.                         --version' -- $cur ) )
  8713.                 else
  8714.                     _filedir -d
  8715.                 fi
  8716.                 ;;
  8717.         esac
  8718.     fi
  8719. }
  8720. complete -F _cpio cpio
  8721. }
  8722.  
  8723. # id(1) completion
  8724. #
  8725. have id &&
  8726. _id()
  8727. {
  8728.     local cur
  8729.  
  8730.     COMPREPLY=()
  8731.     cur=`_get_cword`
  8732.  
  8733.     if [[ "$cur" == -* ]]; then
  8734.         COMPREPLY=( $( compgen -W '-a -g --group -G --groups -n --name\
  8735.             -r --real -u --user --help --version' -- $cur ) )
  8736.     else
  8737.         COMPREPLY=( $( compgen -u $cur  ) )
  8738.     fi
  8739. } &&
  8740. complete -F _id id
  8741.  
  8742. # getent(1) completion
  8743. #
  8744. have getent &&
  8745. _getent()
  8746. {
  8747.     local cur prev
  8748.  
  8749.     COMPREPLY=()
  8750.     cur=`_get_cword`
  8751.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8752.  
  8753.     case $prev in
  8754.         passwd)
  8755.             COMPREPLY=( $( compgen -u $cur  ) )
  8756.             return 0
  8757.             ;;
  8758.         group)
  8759.             COMPREPLY=( $( compgen -g $cur  ) )
  8760.             return 0
  8761.             ;;
  8762.         services)
  8763.             COMPREPLY=( $( compgen -s $cur  ) )
  8764.             return 0
  8765.             ;;
  8766.         hosts)
  8767.             COMPREPLY=( $( compgen -A hostname $cur  ) )
  8768.             return 0
  8769.             ;;
  8770.         protocols)
  8771.             COMPREPLY=( $( getent protocols | awk '{print $1}' | grep "^$cur" ) )
  8772.             return 0
  8773.             ;;
  8774.         networks)
  8775.             COMPREPLY=( $( getent networks | awk '{print $1}' | grep "^$cur" ) )
  8776.             return 0
  8777.             ;;
  8778.     esac
  8779.  
  8780.  
  8781.     if [ $COMP_CWORD -eq 1 ]; then
  8782.         COMPREPLY=( $( compgen -W 'passwd group hosts services protocols networks' -- $cur ) )
  8783.     fi
  8784. } &&
  8785. complete -F _getent getent
  8786.  
  8787. # ntpdate(1) completion
  8788. #
  8789. have ntpdate &&
  8790. _ntpdate()
  8791. {
  8792.     local cur prev
  8793.  
  8794.     COMPREPLY=()
  8795.     cur=`_get_cword`
  8796.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8797.  
  8798.     case $prev in
  8799.         -k)
  8800.             _filedir
  8801.             return 0
  8802.             ;;
  8803.         -U)
  8804.             COMPREPLY=( $( compgen -u $cur  ) )
  8805.             return 0
  8806.             ;;
  8807.     esac
  8808.  
  8809.     if [[ "$cur" == -* ]]; then
  8810.         COMPREPLY=( $( compgen -W '-4 -6 -b -B -d -Q -q -s -u -v -a\
  8811.             -e -k -p -o -r -t' -- $cur ) )
  8812.     else
  8813.         _known_hosts
  8814.     fi
  8815. } &&
  8816. complete -F _ntpdate ntpdate
  8817.  
  8818. # smartctl(8) completion
  8819. #
  8820. have smartctl && {
  8821. _smartctl_quietmode()
  8822. {
  8823.     COMPREPLY=( $( compgen -W 'errorsonly silent' -- $cur ) )
  8824. }
  8825. _smartctl_device()
  8826. {
  8827.     COMPREPLY=( $( compgen -W 'ata scsi 3ware' -- $cur ) )
  8828. }
  8829. _smartctl_tolerance()
  8830. {
  8831.     COMPREPLY=( $( compgen -W 'warn exit ignore' -- $cur ) )
  8832. }
  8833. _smartctl_badsum()
  8834. {
  8835.     COMPREPLY=( $( compgen -W 'normal conservative permissive verypermissive' -- $cur ) )
  8836. }
  8837. _smartctl_report()
  8838. {
  8839.     COMPREPLY=( $( compgen -W 'ioctl ataioctl scsiioctl' -- $cur ) )
  8840. }
  8841. _smartctl_feature()
  8842. {
  8843.     COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  8844. }
  8845. _smartctl_log()
  8846. {
  8847.     COMPREPLY=( $( compgen -W 'error selftest selective directory' -- $cur ) )
  8848. }
  8849. _smartctl_vendorattribute()
  8850. {
  8851.     COMPREPLY=( $( compgen -W 'help 9,minutes 9,seconds 9,halfminutes \
  8852.         9,temp 192,emergencyretractcyclect 193,loadunload \
  8853.         194,10xCelsius 194,unknown 198,offlinescanuncsectorct \
  8854.         200,writeerrorcount 201,detectedtacount 220,temp' -- $cur ) )
  8855. }
  8856. _smartctl_firmwarebug()
  8857. {
  8858.     COMPREPLY=( $( compgen -W 'none samsung samsung2' -- $cur ) )
  8859. }
  8860. _smartctl_presets()
  8861. {
  8862.     COMPREPLY=( $( compgen -W 'use ignore show showall' -- $cur ) )
  8863. }
  8864. _smartctl_test()
  8865. {
  8866.     COMPREPLY=( $( compgen -W 'offline short long conveyance select afterselect,on afterselect,off pending' -- $cur ) )
  8867. }
  8868.  
  8869. _smartctl()
  8870. {
  8871.     local cur prev
  8872.  
  8873.     COMPREPLY=()
  8874.     cur=`_get_cword`
  8875.     prev=${COMP_WORDS[COMP_CWORD-1]}
  8876.  
  8877.     # --name value style option
  8878.     case "$prev" in
  8879.         -q)
  8880.             _smartctl_quietmode
  8881.             ;;
  8882.         -d)
  8883.             _smartctl_device
  8884.             return 0
  8885.             ;;
  8886.         -t)
  8887.             _smartctl_tolerance
  8888.             return 0
  8889.             ;;
  8890.         -b)
  8891.             _smartctl_badsum
  8892.             return 0
  8893.             ;;
  8894.         -r)
  8895.             _smartctl_report
  8896.             return 0
  8897.             ;;
  8898.         -s)
  8899.             _smartctl_feature
  8900.             return 0
  8901.             ;;
  8902.         -o)
  8903.             _smartctl_feature
  8904.             return 0
  8905.             ;;
  8906.         -S)
  8907.             _smartctl_feature
  8908.             return 0
  8909.             ;;
  8910.         -l)
  8911.             _smartctl_log
  8912.             return 0
  8913.             ;;
  8914.         -v)
  8915.             _smartctl_vendorattribute
  8916.             return 0
  8917.             ;;
  8918.         -F)
  8919.             _smartctl_firmwarebug
  8920.             return 0
  8921.             ;;
  8922.         -P)
  8923.             _smartctl_presets
  8924.             return 0
  8925.             ;;
  8926.         -t)
  8927.             _smartctl_test
  8928.             return 0
  8929.             ;;
  8930.     esac
  8931.  
  8932.     # --name=value style option
  8933.     if [[ "$cur" == *=* ]]; then
  8934.         prev=${cur/=*/}
  8935.         cur=${cur/*=/}
  8936.         case "$prev" in
  8937.             --quietmode)
  8938.                 _smartctl_quietmode
  8939.                 return 0
  8940.                 ;;
  8941.             --device)
  8942.                 _smartctl_device
  8943.                 return 0
  8944.                 ;;
  8945.             --tolerance)
  8946.                 _smartctl_tolerance
  8947.                 return 0
  8948.                 ;;
  8949.             --badsum)
  8950.                 _smartctl_badsum
  8951.                 return 0
  8952.                 ;;
  8953.             --report)
  8954.                 _smartctl_report
  8955.                 return 0
  8956.                 ;;
  8957.             --smart)
  8958.                 _smartctl_feature
  8959.                 return 0
  8960.                 ;;
  8961.             --offlineauto)
  8962.                 _smartctl_feature
  8963.                 return 0
  8964.                 ;;
  8965.             --saveauto)
  8966.                 _smartctl_feature
  8967.                 return 0
  8968.                 ;;
  8969.             --log)
  8970.                 _smartctl_log
  8971.                 return 0
  8972.                 ;;
  8973.             --vendorattribute)
  8974.                 _smartctl_vendorattribute
  8975.                 return 0
  8976.                 ;;
  8977.             --firmwarebug)
  8978.                 _smartctl_firmwarebug
  8979.                 return 0
  8980.                 ;;
  8981.             --presets)
  8982.                 _smartctl_presets
  8983.                 return 0
  8984.                 ;;
  8985.             --test)
  8986.                 _smartctl_test
  8987.                 return 0
  8988.                 ;;
  8989.         esac
  8990.     fi
  8991.  
  8992.  
  8993.     if [[ "$cur" == -* ]]; then
  8994.         COMPREPLY=( $( compgen -W '-h --help --usage -V --version \
  8995.             --copyright --license-i --info -a --all -q \
  8996.             --quietmode= -d --device= -T --tolerance= -b --badsum= \
  8997.             -r --report= -s --smart= -o --offlineauto= -S \
  8998.             --saveauto= -H --health -c --capabilities -A \
  8999.             --attributes -l --log= -v --vendorattribute= -F \
  9000.             --firmwarebug= -P --presets= -t --test= -C \
  9001.             --captive -X --abort' -- $cur ) )
  9002.     else
  9003.         cur=${cur:=/dev/}
  9004.         _filedir
  9005.     fi
  9006. }
  9007. complete -F _smartctl smartctl
  9008. }
  9009.  
  9010. # vncviewer(1) completion
  9011. #
  9012. have vncviewer &&
  9013. _vncviewer()
  9014. {
  9015.     local cur prev
  9016.     local -a config
  9017.  
  9018.     COMPREPLY=()
  9019.     cur=`_get_cword`
  9020.     prev=${COMP_WORDS[COMP_CWORD-1]}
  9021.  
  9022.     case "$prev" in
  9023.     -via)
  9024.        _known_hosts -a
  9025.        ;;
  9026.     *)
  9027.        # ssh into the the server, find and ping the broadcast address, then
  9028.        # sort and show the results.
  9029.        COMPREPLY=( $( ssh -o 'Batchmode yes' $prev \
  9030.               "ping -bnc 4 255.255.255.255" 2>/dev/null | \
  9031.               awk -F ' ' '{print $4}' | \
  9032.               sort -n | uniq | egrep '[0-9]+\.[0-9]+\.' 2>/dev/null ) )
  9033.     esac
  9034.  
  9035.     return 0
  9036. } &&
  9037. complete -F _vncviewer vncviewer
  9038.  
  9039. # sysctl(8) completion
  9040. #
  9041. have sysctl &&
  9042. _sysctl()
  9043. {
  9044.     local cur
  9045.  
  9046.     COMPREPLY=()
  9047.     cur=`_get_cword`
  9048.  
  9049.     COMPREPLY=( $( compgen -W "$(sysctl -N -a 2>/dev/null)" -- $cur ) )
  9050.  
  9051.     return 0
  9052. } &&
  9053. complete -F _sysctl sysctl
  9054.  
  9055. # update-rc.d(8) completion
  9056. #
  9057. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  9058. #
  9059. have update-rc.d &&
  9060. _update_rc_d()
  9061. {
  9062.     local cur prev sysvdir services options valid_options
  9063.  
  9064.     cur=`_get_cword`
  9065.     prev=${COMP_WORDS[COMP_CWORD-1]}
  9066.  
  9067.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  9068.     || sysvdir=/etc/init.d
  9069.  
  9070.     services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
  9071.     services=( ${services[@]#$sysvdir/} )
  9072.     options=( -f -n )
  9073.  
  9074.     if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
  9075.     valid_options=( $( \
  9076.         echo "${COMP_WORDS[@]} ${options[@]}" \
  9077.         | tr " " "\n" \
  9078.         | sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
  9079.         | sort | uniq -u \
  9080.         ) )
  9081.     COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
  9082.         -X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- $cur ) )
  9083.     elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
  9084.     COMPREPLY=( $( compgen -W 'remove defaults start stop' -- $cur ) )
  9085.     elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
  9086.     COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  9087.     elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
  9088.     COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  9089.     elif [[ "$prev" == defaults && -z "$cur" ]]; then
  9090.     COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
  9091.     elif [[ "$prev" == ?(start|stop) ]]; then
  9092.     if [[ "$cur" == [0-9] || -z "$cur" ]]; then
  9093.         COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  9094.     elif [[ "$cur" == [0-9][0-9] ]]; then
  9095.         COMPREPLY=( $cur )
  9096.     else
  9097.         COMPREPLY=()
  9098.     fi
  9099.     elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
  9100.     if [[ -z "$cur" ]]; then
  9101.         if [[ $prev == [0-9][0-9] ]]; then
  9102.         COMPREPLY=( 0 1 2 3 4 5 6 S )
  9103.         else
  9104.         COMPREPLY=( 0 1 2 3 4 5 6 S . )
  9105.         fi
  9106.     elif [[ "$cur" == [0-6S.] ]]; then
  9107.         COMPREPLY=( $cur )
  9108.     else
  9109.         COMPREPLY=()
  9110.     fi
  9111.     elif [[ "$prev" == "." ]]; then
  9112.     COMPREPLY=( $(compgen -W "start stop" -- $cur) )
  9113.     else
  9114.     COMPREPLY=()
  9115.     fi
  9116.  
  9117.     return 0
  9118. } &&
  9119. complete -F _update_rc_d update-rc.d
  9120.  
  9121. # invoke-rc.d(8) completion
  9122. #
  9123. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  9124. #
  9125. have invoke-rc.d &&
  9126. _invoke_rc_d()
  9127. {
  9128.     local cur prev sysvdir services options valid_options
  9129.  
  9130.     cur=`_get_cword`
  9131.     prev=${COMP_WORDS[COMP_CWORD-1]}
  9132.  
  9133.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  9134.     || sysvdir=/etc/init.d
  9135.  
  9136.     services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm*)) )
  9137.     services=( ${services[@]#$sysvdir/} )
  9138.     options=( --help --quiet --force --try-anyway --disclose-deny --query --no-fallback )
  9139.  
  9140.     if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then
  9141.     valid_options=( $( \
  9142.         echo ${COMP_WORDS[@]} ${options[@]} \
  9143.         | tr " " "\n" \
  9144.         | sed -ne "/$( echo ${options[@]} | sed "s/ /\\\\|/g" )/p" \
  9145.         | sort | uniq -u \
  9146.         ) )
  9147.     COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- \
  9148.         $cur ) )
  9149.     elif [ -x $sysvdir/$prev ]; then
  9150.     COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
  9151.                         s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
  9152.                         $sysvdir/$prev`' -- \
  9153.         $cur ) )
  9154.     else
  9155.     COMPREPLY=()
  9156.     fi
  9157.  
  9158.     return 0
  9159. } &&
  9160. complete -F _invoke_rc_d invoke-rc.d
  9161.  
  9162. # minicom(1) completion
  9163. #
  9164. have minicom &&
  9165. _minicom()
  9166. {
  9167.     local cur prev
  9168.  
  9169.     COMPREPLY=()
  9170.     cur=`_get_cword`
  9171.     prev=${COMP_WORDS[COMP_CWORD-1]}
  9172.  
  9173.     case $prev in
  9174.         -@(a|c))
  9175.             COMPREPLY=( $( compgen -W 'on off' -- $cur ) )
  9176.             return 0
  9177.             ;;
  9178.         -@(S|C))
  9179.             _filedir
  9180.             return 0
  9181.             ;;
  9182.         -P)
  9183.             COMPREPLY=( $( command ls /dev/tty* ) )
  9184.             COMPREPLY=( $( compgen -W '${COMPREPLY[@]} ${COMPREPLY[@]#/dev/}' -- $cur ) )
  9185.             return 0
  9186.             ;;
  9187.     esac
  9188.  
  9189.  
  9190.     if [[ "$cur" == -* ]]; then
  9191.         COMPREPLY=( $( compgen -W '-s -o -m -M -z -l -L -w -a -t \
  9192.             -c -S -d -p -C -T -8' -- $cur ) )
  9193.     else
  9194.         COMPREPLY=( $( command ls /etc/minicom/minirc.* 2>/dev/null | sed -e 's|/etc/minicom/minirc.||' | grep "^$cur" ) )
  9195.     fi
  9196. } &&
  9197. complete -F _minicom minicom
  9198.  
  9199. # svn completion
  9200. #
  9201. have svn &&
  9202. {
  9203. _svn()
  9204. {
  9205.     local cur prev commands options command
  9206.  
  9207.     COMPREPLY=()
  9208.     cur=`_get_cword`
  9209.  
  9210.     commands='add blame praise annotate ann cat checkout co cleanup commit \
  9211.         ci copy cp delete del remove rm diff di export help ? h import \
  9212.         info list ls lock log merge mkdir move mv rename ren \
  9213.         propdel pdel pd propedit pedit pe propget pget pg \
  9214.         proplist plist pl propset pset ps resolved revert \
  9215.         status stat st switch sw unlock update up'
  9216.  
  9217.     if [[ $COMP_CWORD -eq 1 ]] ; then
  9218.         if [[ "$cur" == -* ]]; then
  9219.             COMPREPLY=( $( compgen -W '--version' -- $cur ) )
  9220.         else
  9221.             COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9222.         fi
  9223.     else
  9224.  
  9225.         prev=${COMP_WORDS[COMP_CWORD-1]}
  9226.         case $prev in
  9227.             --config-dir)
  9228.                 _filedir -d
  9229.                 return 0;
  9230.                 ;;
  9231.             -@(F|-file|-targets))
  9232.                 _filedir
  9233.                 return 0;
  9234.                 ;;
  9235.             --encoding)
  9236.                 COMPREPLY=( $( compgen -W \
  9237.                     '$( iconv --list | sed -e "s@//@@;" )' \
  9238.                     -- "$cur" ) )
  9239.                 return 0;
  9240.                 ;;
  9241.             --@(editor|diff|diff3)-cmd)
  9242.                 COMP_WORDS=(COMP_WORDS[0] $cur)
  9243.                 COMP_CWORD=1
  9244.                 _command
  9245.                 return 0;
  9246.                 ;;
  9247.         esac
  9248.  
  9249.         command=${COMP_WORDS[1]}
  9250.  
  9251.         if [[ "$cur" == -* ]]; then
  9252.             # possible options for the command
  9253.             case $command in
  9254.                 add)
  9255.                     options='--auto-props --no-auto-props \
  9256.                         --force --targets --no-ignore \
  9257.                         --non-recursive -N -q --quiet'
  9258.                     ;;
  9259.                 @(blame|annotate|ann|praise))
  9260.                     options='-r --revisions --username \
  9261.                         --password --no-auth-cache \
  9262.                         --non-interactive -v \
  9263.                         --verbose --incremental --xml'
  9264.                     ;;
  9265.                 cat)
  9266.                     options='-r --revision --username \
  9267.                         --password --no-auth-cache \
  9268.                         --non-interactive'
  9269.                     ;;
  9270.                 @(checkout|co))
  9271.                     options='-r --revision -q --quiet -N \
  9272.                         --non-recursive --username \
  9273.                         --password --no-auth-cache \
  9274.                         --non-interactive \
  9275.                         --ignore-externals'
  9276.                     ;;
  9277.                 cleanup)
  9278.                     options='--diff3-cmd'
  9279.                     ;;
  9280.                 @(commit|ci))
  9281.                     options='-m --message -F --file \
  9282.                         --encoding --force-log -q \
  9283.                         --quiet --non-recursive -N \
  9284.                         --targets --editor-cmd \
  9285.                         --username --password \
  9286.                         --no-auth-cache \
  9287.                         --non-interactive --no-unlock'
  9288.                     ;;
  9289.                 @(copy|cp))
  9290.                     options='-m --message -F --file \
  9291.                         --encoding --force-log -r \
  9292.                         --revision -q --quiet \
  9293.                         --editor-cmd -username \
  9294.                         --password --no-auth-cache \
  9295.                         --non-interactive'
  9296.                     ;;
  9297.                 @(delete|del|remove|rm))
  9298.                     options='--force -m --message -F \
  9299.                         --file --encoding --force-log \
  9300.                         -q --quiet --targets \
  9301.                         --editor-cmd -username \
  9302.                         --password --no-auth-cache \
  9303.                         --non-interactive'
  9304.                     ;;
  9305.                 @(diff|di))
  9306.                     options='-r --revision -x --extensions \
  9307.                         --diff-cmd --no-diff-deleted \
  9308.                         -N --non-recursive --username \
  9309.                         --password --no-auth-cache \
  9310.                         --non-interactive --force \
  9311.                         --old --new --notice-ancestry'
  9312.                     ;;
  9313.                 export)
  9314.                     options='-r --revision -q --quiet \
  9315.                         --username --password \
  9316.                         --no-auth-cache \
  9317.                         --non-interactive -N \
  9318.                         --non-recursive --force \
  9319.                         --native-eol --ignore-externals'
  9320.                     ;;
  9321.                 import)
  9322.                     options='--auto-props --no-auto-props \
  9323.                         -m --message -F --file \
  9324.                         --encoding --force-log -q \
  9325.                         --quiet --non-recursive \
  9326.                         --no-ignore --editor-cmd \
  9327.                         --username --password \
  9328.                         --no-auth-cache \
  9329.                         --non-interactive'
  9330.                     ;;
  9331.                 info)
  9332.                     options='--username --password \
  9333.                         --no-auth-cache \
  9334.                         --non-interactive -r \
  9335.                         --revision --xml --targets \
  9336.                         -R --recursive --incremental'
  9337.                     ;;
  9338.                 @(list|ls))
  9339.                     options='-r --revision -v --verbose -R \
  9340.                         --recursive --username \
  9341.                         --password --no-auth-cache \
  9342.                         --non-interactive \
  9343.                         --incremental --xml'
  9344.                     ;;
  9345.                 lock)
  9346.                     options='-m --message -F --file \
  9347.                         --encoding --force-log \
  9348.                         --targets --force --username \
  9349.                         --password --no-auth-cache \
  9350.                         --non-interactive'
  9351.                     ;;
  9352.                 log)
  9353.                     options='-r --revision -v --verbose \
  9354.                         --targets --username \
  9355.                         --password --no-auth-cache \
  9356.                         --non-interactive \
  9357.                         --stop-on-copy --incremental \
  9358.                         --xml -q --quiet --limit'
  9359.                     ;;
  9360.                 merge)
  9361.                     options='-r --revision -N \
  9362.                         --non-recursive -q --quiet \
  9363.                         --force --dry-run --diff3-cmd \
  9364.                         --username --password \
  9365.                         --no-auth-cache \
  9366.                         --non-interactive \
  9367.                         --ignore-ancestry'
  9368.                     ;;
  9369.                 mkdir)
  9370.                     options='-m --message -F --file \
  9371.                         --encoding --force-log -q \
  9372.                         --quiet --editor-cmd \
  9373.                         --username --password \
  9374.                         --no-auth-cache \
  9375.                         --non-interactive'
  9376.                     ;;
  9377.                 @(move|mv|rename|ren))
  9378.                     options='-m --message -F --file \
  9379.                         --encoding --force-log -r \
  9380.                         --revision -q --quiet \
  9381.                         --force --editor-cmd \
  9382.                         --username --password \
  9383.                         --no-auth-cache \
  9384.                         --non-interactive'
  9385.                     ;;
  9386.                 @(propdel|pdel|pd))
  9387.                     options='-q --quiet -R --recursive -r \
  9388.                         --revision --revprop \
  9389.                         --username --password \
  9390.                         --no-auth-cache \
  9391.                         --non-interactive'
  9392.                     ;;
  9393.                 @(propedit|pedit|pe))
  9394.                     options='-r --revision --revprop \
  9395.                         --encoding --editor-cmd \
  9396.                         --username --password \
  9397.                         --no-auth-cache \
  9398.                         --non-interactive --force'
  9399.                     ;;
  9400.                 @(propget|pget|pg))
  9401.                     options='-R --recursive -r --revision \
  9402.                         --revprop --strict --username \
  9403.                         --password --no-auth-cache \
  9404.                         --non-interactive'
  9405.                     ;;
  9406.                 @(proplist|plist|pl))
  9407.                     options='-v --verbose -R --recursive \
  9408.                         -r --revision --revprop -q \
  9409.                         --quiet --username --password \
  9410.                         --no-auth-cache \
  9411.                         --non-interactive'
  9412.                     ;;
  9413.                 @(propset|pset|ps))
  9414.                     options='-F --file -q --quiet \
  9415.                         --targets -R --recursive \
  9416.                         --revprop --encoding \
  9417.                         --username --password \
  9418.                         --no-auth-cache \
  9419.                         --non-interactive -r \
  9420.                         --revision --force'
  9421.                     ;;
  9422.                 resolved)
  9423.                     options='--targets -R --recursive -q \
  9424.                         --quiet'
  9425.                     ;;
  9426.                 revert)
  9427.                     options='--targets -R --recursive -q \
  9428.                         --quiet'
  9429.                     ;;
  9430.                 @(status|stat|st))
  9431.                     options='-u --show-updates -v \
  9432.                         --verbose -N --non-recursive \
  9433.                         -q --quiet --username \
  9434.                         --password --no-auth-cache \
  9435.                         --non-interactive --no-ignore \
  9436.                         --ignore-externals \
  9437.                         --incremental --xml'
  9438.                     ;;
  9439.                 @(switch|sw))
  9440.                     options='--relocate -r --revision -N \
  9441.                         --non-recursive -q --quiet \
  9442.                         --username --password \
  9443.                         --no-auth-cache \
  9444.                         --non-interactive --diff3-cmd'
  9445.                     ;;
  9446.                 unlock)
  9447.                     options='--targets --force --username \
  9448.                         --password --no-auth-cache \
  9449.                         --non-interactive'
  9450.                     ;;
  9451.                 @(update|up))
  9452.                     options='-r --revision -N \
  9453.                         --non-recursive -q --quiet \
  9454.                         --username --password \
  9455.                         --no-auth-cache \
  9456.                         --non-interactive \
  9457.                         --diff3-cmd --ignore-externals'
  9458.                     ;;
  9459.             esac
  9460.             options="$options --help -h --config-dir"
  9461.  
  9462.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  9463.         else
  9464.             if [[ "$command" == @(help|h|\?) ]]; then
  9465.                 COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9466.             else
  9467.                 _filedir
  9468.             fi
  9469.         fi
  9470.     fi
  9471.  
  9472.     return 0
  9473. }
  9474. complete -F _svn $default svn
  9475.  
  9476. _svnadmin()
  9477. {
  9478.     local cur prev commands options mode
  9479.  
  9480.     COMPREPLY=()
  9481.     cur=`_get_cword`
  9482.  
  9483.     commands='create deltify dump help ? hotcopy list-dblogs \
  9484.         list-unused-dblogs load lslocks lstxns recover rmlocks \
  9485.         rmtxns setlog verify'
  9486.  
  9487.     if [[ $COMP_CWORD -eq 1 ]] ; then
  9488.         if [[ "$cur" == -* ]]; then
  9489.             COMPREPLY=( $( compgen -W '--version' -- $cur ) )
  9490.         else
  9491.             COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9492.         fi
  9493.     else
  9494.         prev=${COMP_WORDS[COMP_CWORD-1]}
  9495.         case $prev in
  9496.             --config-dir)
  9497.                 _filedir -d
  9498.                 return 0;
  9499.                 ;;
  9500.             --fs-type)
  9501.                 COMPREPLY=( $( compgen -W 'fsfs bdb' -- $cur ) )
  9502.                 return 0;
  9503.                 ;;
  9504.         esac
  9505.  
  9506.         command=${COMP_WORDS[1]}
  9507.  
  9508.         if [[ "$cur" == -* ]]; then
  9509.             # possible options for the command
  9510.             case $command in
  9511.                 create)
  9512.                     options='--bdb-txn-nosync \
  9513.                         --bdb-log-keep --config-dir \
  9514.                         --fs-type'
  9515.                     ;;
  9516.                 deltify)
  9517.                     options='-r --revision -q --quiet'
  9518.                     ;;
  9519.                 dump)
  9520.                     options='-r --revision --incremental \
  9521.                         -q --quiet --deltas'
  9522.                     ;;
  9523.                 hotcopy)
  9524.                     options='--clean-logs'
  9525.                     ;;
  9526.                 load)
  9527.                     options='--ignore-uuid --force-uuid \
  9528.                         --parent-dir -q --quiet \
  9529.                         --use-pre-commit-hook \
  9530.                         --use-post-commit-hook'
  9531.                     ;;
  9532.                 rmtxns)
  9533.                     options='-q --quiet'
  9534.                     ;;
  9535.                 setlog)
  9536.                     options='-r --revision --bypass-hooks'
  9537.                     ;;
  9538.             esac
  9539.  
  9540.             options="$options --help -h"
  9541.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  9542.         else
  9543.             if [[ "$command" == @(help|h|\?) ]]; then
  9544.                 COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9545.             else
  9546.                 _filedir
  9547.             fi
  9548.         fi
  9549.     fi
  9550.  
  9551.     return 0
  9552. }
  9553. complete -F _svnadmin $default svnadmin
  9554.  
  9555. _svnlook()
  9556. {
  9557.     local cur prev commands options mode
  9558.  
  9559.     COMPREPLY=()
  9560.     cur=`_get_cword`
  9561.  
  9562.     commands='author cat changed date diff dirs-changed help ? h history \
  9563.         info lock log propget pget pg proplist plist pl tree uuid \
  9564.         youngest'
  9565.  
  9566.     if [[ $COMP_CWORD -eq 1 ]] ; then
  9567.         if [[ "$cur" == -* ]]; then
  9568.             COMPREPLY=( $( compgen -W '--version' -- $cur ) )
  9569.         else
  9570.             COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9571.         fi
  9572.     else
  9573.         command=${COMP_WORDS[1]}
  9574.  
  9575.         if [[ "$cur" == -* ]]; then
  9576.             # possible options for the command
  9577.             case $command in
  9578.                 @(author|cat|date|dirs-changed|info|log))
  9579.                     options='-r --revision -t \
  9580.                         --transaction'
  9581.                     ;;
  9582.                 changed)
  9583.                     options='-r --revision -t \
  9584.                         --transaction --copy-info'
  9585.                     ;;
  9586.                 diff)
  9587.                     options='-r --revision -t \
  9588.                         --transaction \
  9589.                         --no-diff-deleted \
  9590.                         --no-diff-added \
  9591.                         --diff-copy-from'
  9592.                     ;;
  9593.                 history)
  9594.                     options='-r --revision --show-ids'
  9595.                     ;;
  9596.                 prop@(get|list))
  9597.                     options='-r --revision -t \
  9598.                         --transaction --revprop'
  9599.                     ;;
  9600.                 tree)
  9601.                     options='-r --revision -t \
  9602.                         --transaction --show-ids \
  9603.                         --full-paths'
  9604.                     ;;
  9605.             esac
  9606.  
  9607.             options="$options --help -h"
  9608.             COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  9609.         else
  9610.             if [[ "$command" == @(help|h|\?) ]]; then
  9611.                 COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  9612.             else
  9613.                 _filedir
  9614.             fi
  9615.         fi
  9616.     fi
  9617.  
  9618.     return 0
  9619. }
  9620. complete -F _svnlook $default svnlook
  9621. }
  9622.  
  9623. have rrdtool &&
  9624. _rrdtool ()
  9625. {
  9626.     cur=`_get_cword`
  9627.     COMPREPLY=( $( compgen -W 'create update updatev graph dump \
  9628.                                restore last lastupdate first info \
  9629.                                fetch tune resize xport' -- $cur ) )
  9630. } &&
  9631. complete -F _rrdtool rrdtool
  9632.  
  9633. _filedir_xspec()
  9634. {
  9635.     local IFS cur xspec
  9636.  
  9637.     IFS=$'\t\n'
  9638.     COMPREPLY=()
  9639.     cur=`_get_cword`
  9640.  
  9641.     _expand || return 0
  9642.  
  9643.     # get first exclusion compspec that matches this command
  9644.     xspec=$( sed -ne $'/^complete .*[ \t]'${1##*/}$'\([ \t]\|$\)/{p;q;}' \
  9645.           $BASH_COMPLETION )
  9646.     # prune to leave nothing but the -X spec
  9647.     xspec=${xspec#*-X }
  9648.     xspec=${xspec%% *}
  9649.  
  9650.     local toks=( ) tmp
  9651.     
  9652.     while read -r tmp; do
  9653.         [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
  9654.     done < <( compgen -d -- "$(quote_readline "$cur")" )
  9655.  
  9656.     while read -r tmp; do
  9657.         [[ -n $tmp ]] && toks[${#toks[@]}]=$tmp
  9658.     done < <( eval compgen -f -X $xspec -- "\$(quote_readline "\$cur")" )    
  9659.     
  9660.     COMPREPLY=( "${toks[@]}" )
  9661. }
  9662. list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \
  9663.       $BASH_COMPLETION | \
  9664.     # read exclusion compspecs
  9665.     (
  9666.     while read line
  9667.     do
  9668.         # ignore compspecs that are commented out
  9669.         if [ "${line#\#}" != "$line" ]; then continue; fi
  9670.         line=${line%# START exclude*}
  9671.         line=${line%# FINISH exclude*}
  9672.         line=${line##*\'}
  9673.         list=( "${list[@]}" $line )
  9674.     done
  9675.     echo "${list[@]}"
  9676.     )
  9677.      ) )
  9678. # remove previous compspecs
  9679. if [ ${#list[@]} -gt 0 ]; then
  9680.     eval complete -r ${list[@]}
  9681.     # install new compspecs
  9682.     eval complete -F _filedir_xspec $filenames "${list[@]}"
  9683. fi
  9684. unset list
  9685.  
  9686. # source completion directory definitions
  9687. if [ -d $BASH_COMPLETION_DIR -a -r $BASH_COMPLETION_DIR -a \
  9688.      -x $BASH_COMPLETION_DIR ]; then
  9689.     for i in $BASH_COMPLETION_DIR/*; do
  9690.         [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
  9691.             [ \( -f $i -o -h $i \) -a -r $i ] && . $i
  9692.     done
  9693. fi
  9694. unset i
  9695.  
  9696. # source user completion file
  9697. [ $BASH_COMPLETION != ~/.bash_completion -a -r ~/.bash_completion ] \
  9698.     && . ~/.bash_completion
  9699. unset -f have
  9700. unset UNAME RELEASE default dirnames filenames have nospace bashdefault \
  9701.       plusdirs
  9702.  
  9703. set $BASH_COMPLETION_ORIGINAL_V_VALUE
  9704. unset BASH_COMPLETION_ORIGINAL_V_VALUE
  9705.  
  9706. ###  Local Variables:
  9707. ###  mode: shell-script
  9708. ###  End:
  9709.